size_t i = strlen(s) - 1: the (i > 0) guard cannot see the underflow - #832
Merged
Merged
Conversation
An unsigned index seeded with strlen(s) - 1 becomes SIZE_MAX on an empty string, and SIZE_MAX passes the (i > 0) the sites carry. Seed from hts_lastcharoffset() instead, and cover the spelling in the lastchar self-test and its source guard. Closes #821 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Signed-off-by: Xavier Roche <roche@httrack.com>
The declaration pattern cannot see punycode.c, where input_length is declared a dozen lines above the subtraction, so reverting that fix alone left the guard silent. Match an uncast assignment too; the (int) casts in htscore.c and htstools.c are the safe form and stay out. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Signed-off-by: Xavier Roche <roche@httrack.com>
…o fix/strlen-size-t-form-821
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.
Seven sites in
htswizard.cseed asize_tindex withstrlen(x) - 1and then guard the walk-back with(i > 0).SIZE_MAXsatisfies that, so the check the author meant as the emptiness test does nothing. They now seed fromhts_lastcharoffset(), which #819 adds. On any non-empty string it is the same value, so the only behaviour that moves is the empty case that used to read below the buffer.Nothing reaches them today.
ident_url_absolute()returns -1 on an emptyadrand substitutesdefault-index.htmlfor an emptyfil, and that is where the whole invariant lives, since no caller checksfilitself. A producer of an emptyfiladded later would turn three of the sites live at once.punycode.cis the exception and the only out-of-bounds write in the set. RFC 3492's sample harness wants bothPUNYCODE_COSTELLO_RFC3492_INCLUDE_TESTand..._MAIN, and nothing in the tree or the build defines either, so it never compiles. Define both and a stdin line whose first byte is NUL leavesstrlen()at 0, which segfaults on the read atinput[input_length]and would write there next. Checked under ASan against both versions.Every site being latent, the barrier against the idiom coming back is the source guard rather than a crawl: the self-test picks up the
size_tspelling and01_engine-lastchar.testgrows a grep for it.Based on #819 for the helper. A live crash turned up in the same sweep and went out separately as #829.
Closes #821