lienrelatif() reads one byte before its stack buffer on an empty path#729
Merged
Conversation
The trim that walks back to the last '/' starts at `curr + strlen(curr) - 1`, which is `curr - 1` when the path is empty. The loop then dereferences it. An empty path is reachable today: the pre-pass that strips a query does `strncatbuff(newcurr_fil, curr_fil, a - curr_fil)`, so any `curr_fil` starting with '?' hands the walk an empty string. `-#test=relative "dir/page.html" "?x"` under ASan reports the underflow. The read is one byte and the loop stops immediately either way, so the guard changes no output: over the 484 ordered pairs of a 22-value path corpus, run against builds that force the byte before the buffer to 0 and to '/', the guarded and unguarded results are identical. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Signed-off-by: Xavier Roche <roche@httrack.com>
This was referenced Jul 26, 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.
lienrelatif()trims its current-path argument back to the last/, starting fromcurr + strlen(curr) - 1. When the path is empty that iscurr - 1, and the loop dereferences it before the bounds test stops it.The empty path is not hypothetical. The pre-pass that strips a query does
strncatbuff(newcurr_fil, curr_fil, a - curr_fil), so anycurr_filbeginning with?hands the trim an empty string.httrack -#test=relative "dir/page.html" "?x"under ASan reports the underflow on current master.The read is a single byte and the loop exits on its
a > currtest whatever that byte holds, so the guard is behaviour-preserving rather than a behaviour change. Checked rather than assumed: 484 ordered pairs from a 22-value path corpus, run against builds that force the byte before the buffer to0and to'/', produce output identical to the guarded build in both states.Found while working on #712, which reaches the same path from a document with no save name.