Skip to content

fix: prevent null dereference in fuzz test socket initialization#3314

Merged
chenBright merged 1 commit into
apache:masterfrom
Felix-Gong:fix-null-deref-fuzz
May 28, 2026
Merged

fix: prevent null dereference in fuzz test socket initialization#3314
chenBright merged 1 commit into
apache:masterfrom
Felix-Gong:fix-null-deref-fuzz

Conversation

@Felix-Gong
Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: Fix #3114

get_fuzz_socket() in test/fuzzing/fuzz_common.h sets initialized = true unconditionally after the first attempt, even when Socket::Create() or Socket::Address() fails. This causes all subsequent calls to return NULL, and the fuzz harnesses pass this NULL pointer directly to protocol parse functions (e.g., ParseHuluMessage), which dereference it via socket->remote_side(), triggering a SEGV.

What is changed and how it works?

  1. fuzz_common.h: Move initialized = true inside the success branch so that get_fuzz_socket() retries socket creation on failure instead of permanently returning NULL.

  2. All 9 fuzz test files: Add a NULL check for the socket pointer before calling the parse function. If socket creation fails after retry, the test gracefully returns 0 instead of crashing.

Check List

  • Tests (fuzz test syntax verification passes for all 9 modified files)
  • No API changes
  • No breaking changes

Side effects

None. Changes are limited to fuzz test harness code.

- Fix get_fuzz_socket() to only set initialized=true when both
  Socket::Create and Socket::Address succeed, allowing retry on failure
- Add NULL socket checks in all 9 fuzz tests that use get_fuzz_socket()
  to prevent null pointer dereference when socket creation fails

Fixes apache#3114
Copy link
Copy Markdown
Contributor

@chenBright chenBright left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@chenBright chenBright merged commit 3c9ff52 into apache:master May 28, 2026
17 checks passed
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.

Null Dereference

2 participants