ext/snmp: fix infinite loop in snprint_value retry when val_len is zero#21342
Closed
thomasvincent wants to merge 1 commit intophp:masterfrom
Closed
ext/snmp: fix infinite loop in snprint_value retry when val_len is zero#21342thomasvincent wants to merge 1 commit intophp:masterfrom
thomasvincent wants to merge 1 commit intophp:masterfrom
Conversation
When an SNMP variable has val_len == 0 (valid for empty strings), the snprint_value retry loop doubles val_len on each iteration (val_len *= 2). Since 0 * 2 == 0, val_len never grows, the allocated buffer stays at 1 byte, and the 512k break condition is never reached. Fix by clamping val_len to at least sizeof(sbuf) before the loop, ensuring the doubling produces meaningful growth past the initial stack buffer size. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Author
|
Closing to re-evaluate the appropriate disclosure channel. |
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.
When an SNMP variable has
val_len == 0(valid for empty octet strings),the
snprint_valueretry loop doublesval_lenon each iteration(
val_len *= 2). Since0 * 2 == 0,val_lennever grows, theallocated buffer stays at 1 byte, and the
512kbreak condition isnever reached. This causes an infinite loop consuming CPU.
Fix by clamping
val_lento at leastsizeof(sbuf)before the loop,ensuring the doubling produces meaningful growth past the initial stack
buffer size.