ext/snmp: fix buffer overflow in suffix-as-keys OID construction#21341
ext/snmp: fix buffer overflow in suffix-as-keys OID construction#21341thomasvincent wants to merge 1 commit intophp:masterfrom
Conversation
The suffix-as-keys code path in php_snmp builds a dotted OID suffix string by repeatedly calling snprintf into a temporary buffer and appending with strcat into the fixed 2048-byte buf2 array. There is no bounds check, so a deeply nested OID with many large numeric components from a malicious SNMP agent could overflow the stack buffer. Replace the strcat loop with direct snprintf into buf2 at a tracked offset, breaking out of the loop if the buffer is exhausted. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
|
Closing to re-evaluate the appropriate disclosure channel. |
|
Reopening as a defense-in-depth hardening fix. After further analysis, the underlying condition (OID name_length > 128 subidentifiers) is prevented by net-snmp's BER decoder: However, net-snmp has had historical CVEs in its OID parser (e.g., CVE-2019-20892), so this bounds-checked approach provides a safety net against future parser regressions. The fix replaces the unbounded |
|
FWIW, I agree this does not fix an actual issue but is a hardening patch. |
The suffix-as-keys code path in
php_snmpbuilds a dotted OID suffixstring by repeatedly calling
snprintfinto a temporary buffer andappending with
strcatinto the fixed 2048-bytebuf2array. There isno bounds check, so a deeply nested OID with many large numeric
components from a malicious SNMP agent could overflow the stack buffer.
Replace the
strcatloop with directsnprintfintobuf2at a trackedoffset, breaking out of the loop if the buffer would be exhausted.
The
MAX_OID_LEN(128) with maximum-length 32-bit components (10 digitsplus dot each) can produce up to 1408 bytes of suffix text, which fits
within the 2048-byte buffer under normal conditions. This patch adds the
safety net for the pathological case.