Skip to content

fuzz: fix stack-use-after-scope in LLVMFuzzerTestOneInput#881

Closed
oliverchang wants to merge 1 commit intoPCRE2Project:mainfrom
oliverchang:main
Closed

fuzz: fix stack-use-after-scope in LLVMFuzzerTestOneInput#881
oliverchang wants to merge 1 commit intoPCRE2Project:mainfrom
oliverchang:main

Conversation

@oliverchang
Copy link
Copy Markdown

A variable callout_count is declared within the scope of a for loop in the function LLVMFuzzerTestOneInput. The address of this variable is passed to the function pcre2_set_callout() and stored within the variable match_context.

The variable match_context is defined outside the loop, initialized during the first loop iteration, and persists for the second iteration. The address of callout_count is a stale stack location in the second iteration. When pcre2_match() is called in the second iteration, a callback attempts to access this address, resulting in a stack-use-after-scope error.

This patch moves the declaration of callout_count to the function scope, ensuring its lifetime covers the entire duration that match_context is active.

Fixes: https://issues.oss-fuzz.com/issues/478301105

A variable `callout_count` is declared within the scope of a `for` loop in the
function `LLVMFuzzerTestOneInput`. The address of this variable is passed to the
function `pcre2_set_callout()` and stored within the variable `match_context`.

The variable `match_context` is defined outside the loop, initialized during
the first loop iteration, and persists for the second iteration. The address of
`callout_count` is a stale stack location in the second iteration. When
`pcre2_match()` is called in the second iteration, a callback attempts to access
this address, resulting in a stack-use-after-scope error.

This patch moves the declaration of `callout_count` to the function scope,
ensuring its lifetime covers the entire duration that `match_context` is active.

Co-authored-by: CodeMender <codemender-patching@google.com>
Fixes: https://issues.oss-fuzz.com/issues/478301105
@addisoncrump
Copy link
Copy Markdown
Contributor

Please note that this should be considered an AI contribution.

@addisoncrump
Copy link
Copy Markdown
Contributor

@oliverchang, as requested in #882, can you please provide more context for this PR? Is there something in OSS-Fuzz we are not seeing, or was this a spurious patch?

@oliverchang
Copy link
Copy Markdown
Author

@oliverchang, as requested in #882, can you please provide more context for this PR? Is there something in OSS-Fuzz we are not seeing, or was this a spurious patch?

This is a spurious patch caused by a bad bug in our infrastructure.

Please ignore this one, and sorry again for the noise!

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.

2 participants