Skip to content

Fix macOS segfault when a page does not exist - #127

Open
NNoradrenaline wants to merge 2 commits into
tldr-pages:mainfrom
NNoradrenaline:fix/macos-unknown-command-segfault
Open

Fix macOS segfault when a page does not exist#127
NNoradrenaline wants to merge 2 commits into
tldr-pages:mainfrom
NNoradrenaline:fix/macos-unknown-command-segfault

Conversation

@NNoradrenaline

Copy link
Copy Markdown

What does it do?

Fixes an out-of-bounds write in curl_string_init() that can crash the client when a requested page does not exist and the code falls back to the network path.

The response buffer is now initialized with str->str[0] = '\0'; instead of writing one byte past the 1024-byte allocation.

This also adds regression coverage for missing pages and a macOS AddressSanitizer CI job.

Why the change?

Issues #124 and #123 report crashes on macOS when requesting unknown or unavailable pages.

curl_string_init() allocates 1024 bytes, but previously wrote str->str[1024] = '\0';.

Valid indexes are 0 through 1023, so this write is out of bounds and can cause the reported crash.

How can this be tested?

Build the client and run:

./tldr this-page-definitely-does-not-exist-124-regression

Expected behavior:

  • The client prints the normal missing-page message.
  • It exits with status 1.
  • It does not crash.

The added CI coverage also exercises this path under AddressSanitizer on macOS.

Where to start code review?

Start in src/net.c at curl_string_init().

The regression test and sanitizer configuration are in .github/workflows/tests.yml.

Relevant tickets?

Fixes #124

Related: #123

Questions?

None.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

segfaults for unknown commands on macOS

1 participant