Fix Content-Length buffer overflow and add regression tests#45371
Draft
Phlegmelm wants to merge 1 commit into
Draft
Fix Content-Length buffer overflow and add regression tests#45371Phlegmelm wants to merge 1 commit into
Phlegmelm wants to merge 1 commit into
Conversation
|
Hi @Phlegmelm, welcome and thank you for your contribution. We will try to review your Pull Request as quickly as possible. In the meantime, please take a look at the contribution guidelines if you have not done so already. |
- Add content_length_end == -1 guard to prevent length underflow - Add value_len <= 0 guard to reject malformed headers - Clamp copyOut to min(value_len, sizeof(len)-1) to prevent overflow - Replace std::atoi with absl::SimpleAtoi into uint32_t to reject negative, non-numeric, and out-of-range values - Add regression tests: DecodeOverlongContentLengthDoesNotOverflow, DecodeNegativeContentLengthIsRejected Signed-off-by: Lucy <Asherdardenkol@proton.me>
c0b88c5 to
eb9bd8a
Compare
yanavlasov
requested changes
Jun 1, 2026
Contributor
yanavlasov
left a comment
There was a problem hiding this comment.
Thanks. Just a small suggestion to use string_view instead of copying data.
/wait
| // handful of digits, so clamping cannot turn a legitimate value into a | ||
| // smaller-but-valid number (an over-long value is rejected by the parse | ||
| // below as out of range). | ||
| char len[16] = {}; // zero-initialized, so always NUL terminated after copy |
Contributor
There was a problem hiding this comment.
Creating absl::string_view into the content, instead of copying may be better. It will also avoid constructing absl::string_view later on.
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.
Summary
Stack buffer overflow in
Decoder::reassemble()— theContent-Lengthheader value was copied into a fixed-size stack buffer with no length
check, allowing attacker-controlled input to overflow the buffer pre-auth.
Reported via GHSA-rh3p-qxp2-vx3f.
Root cause
contrib/sip_proxy/filters/network/source/decoder.ccpassed anattacker-controlled length directly to
copyOut()without bounds checking:Changes
content_length_end == -1guard to prevent length underflowvalue_len <= 0guard to reject malformed empty/zero-span headersmin(value_len, sizeof(len) - 1)—copyOutcan nolonger write past the buffer
std::atoiwithabsl::SimpleAtoiintouint32_t— rejectsnegative, non-numeric, and out-of-range values
@abseil-cpp//absl/stringstodecoder_libDecodeOverlongContentLengthDoesNotOverflow,DecodeNegativeContentLengthIsRejectedTesting
Not compiled on Windows — verified by review and against the buffer API
contract. Linux build target:
//contrib/sip_proxy/filters/network/test:decoder_test