loader off by one heap overflow#503
Merged
Merged
Conversation
The malloc size calculation in get_or_create_temp_file() allocates
strlen(tmp_dir) + strlen(prefix) + strlen(data.digest) + 2 bytes,
but the constructed path "tmp_dir/prefix-digest\0" requires +3 bytes
(for '/', '-', and the NUL terminator), not +2.
This causes a 1-byte heap-buffer-overflow when strcat writes the NUL
terminator of data.digest past the end of the allocated buffer.
Make the arithmetic explicit by writing each component's length
separately (+1 for each separator and the terminator), matching the
four strcat calls that follow.
The sister function create_temp_file() is not affected: its format
"tmp_dir/prefix.XXXXXX" only has one separator ('/'), and ".XXXXXX"
is already measured by strlen(".XXXXXX").
Fixes #492
Benchmark results for collatzParameters
SummaryFound 0 performance improvements and 0 performance regressions! Performance is the same for 1 metrics, 0 unstable metrics. See unchanged results
|
Benchmark results for BadBoggleSolver_runParameters
SummaryFound 0 performance improvements and 0 performance regressions! Performance is the same for 1 metrics, 0 unstable metrics. See unchanged results
|
nsavoire
approved these changes
Mar 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
replaces the following PR
Motivation
Refer to original PR