Skip to content

loader off by one heap overflow#503

Merged
r1viollet merged 2 commits into
mainfrom
r1viollet/fix/loader-off-by-one-heap-overflow
Mar 4, 2026
Merged

loader off by one heap overflow#503
r1viollet merged 2 commits into
mainfrom
r1viollet/fix/loader-off-by-one-heap-overflow

Conversation

@r1viollet

Copy link
Copy Markdown
Collaborator

What does this PR do?

replaces the following PR

Motivation

Refer to original PR

xroche and others added 2 commits February 25, 2026 22:06
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
@pr-commenter

pr-commenter Bot commented Mar 4, 2026

Copy link
Copy Markdown

Benchmark results for collatz

Parameters

Baseline Candidate
config baseline candidate
profiler-version ddprof 0.23.0+073b5f11.100306450 ddprof 0.23.0+413a6b2a.100332098

Summary

Found 0 performance improvements and 0 performance regressions! Performance is the same for 1 metrics, 0 unstable metrics.

See unchanged results
scenario Δ mean execution_time
scenario:ddprof -S bench-collatz --preset cpu_only collatz_runner.sh same

@pr-commenter

pr-commenter Bot commented Mar 4, 2026

Copy link
Copy Markdown

Benchmark results for BadBoggleSolver_run

Parameters

Baseline Candidate
config baseline candidate
profiler-version ddprof 0.23.0+073b5f11.100306450 ddprof 0.23.0+413a6b2a.100332098

Summary

Found 0 performance improvements and 0 performance regressions! Performance is the same for 1 metrics, 0 unstable metrics.

See unchanged results
scenario Δ mean execution_time
scenario:ddprof -S bench-bad-boggle-solver BadBoggleSolver_run work 1000 same

@r1viollet
r1viollet merged commit 1eae27e into main Mar 4, 2026
3 checks passed
@r1viollet
r1viollet deleted the r1viollet/fix/loader-off-by-one-heap-overflow branch March 4, 2026 14:48
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.

3 participants