Fix out-of-bounds read on malformed uuencode "begin" line#55
Open
iliaal wants to merge 1 commit into
Open
Conversation
The three uudecode loops (mailparse_msg_extract_uue, _enum_uue and mailparse_uudecode_all) matched a "begin " prefix (6 bytes) and then unconditionally read the filename at buffer[10], assuming the "begin <mode> <name>" layout. A short line such as "begin 644\n" (strlen 10) put buffer[10] at or past the NUL terminator, reading into stack/heap garbage. The subsequent trailing-whitespace trim (`while (isspace(origfilename[len-1]))`) could also underflow to origfilename[-1] when the filename was empty. Clamp the filename offset to the actual line length and guard the trim loop with len > 0. Also cast the isspace() argument to unsigned char to avoid UB on bytes with the high bit set.
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.
The three uudecode loops (
mailparse_msg_extract_uue,_enum_uue,mailparse_uudecode_all) matched a 6-bytebeginprefix and then read the filename unconditionally atbuffer[10], assuming abegin <mode> <name>layout. A short line such asbegin 644\n(strlen 10) putsbuffer[10]at or past the NUL terminator, reading into stack garbage; the trailing-whitespace trim could also underflow toorigfilename[-1]on an empty filename. Both are reachable from attacker-controlled message bodies.Clamp the filename offset to the actual line length (
&buffer[len > 10 ? 10 : len]), guard the trim loop withlen > 0, and cast theisspace()argument tounsigned char.