Repository navigation
por: stop reading past the number buffer in read_double_with_peek - #428
Merged
Merged
Conversation
read_double_with_peek collects a number into buffer[100] up to the terminating '/' but never NUL-terminates it. When readstat_por_parse_double rejects the string and an error handler is set, the error message passes buffer to a bare %s, so snprintf reads past the bytes taken from the file into the rest of the stack frame and copies them into the message. Print buffer with the length that was read, as the conversion error just above already does.
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.
read_double_with_peekin the POR reader collects a number into the stack arraybuffer[100]up to the terminating/, but never NUL-terminates it. Whenreadstat_por_parse_doublerejects the string and an error handler is installed, the message passesbufferto a bare%s, sosnprintfreads past the bytes taken from the file into the unused tail ofbufferand the neighbouringutf8_buffer, and copies that stack data into the message given to the handler. A .por file whose numeric field is 98Xcharacters followed by/is enough:readstat bad.por out.csv(the CLI always sets an error handler) stops with an ASan stack-buffer-overflow READ atreadstat_por_read.c:141. The fuzz targets don't install an error handler, which is likely why this hasn't come up there.Print
bufferwith the length that was actually read, the same way the conversion error a few lines up already does. With the change the same file reportsError parsing double string (length=99): XXX.../ [XXX.../]and still fails withREADSTAT_ERROR_PARSE.test_readstat,test_dta_days,test_sav_dateandtest_double_decimalspass under ASan/UBSan.