ext/snmp: hardening: replace unbounded strcat with offset-tracked snprintf#21341
ext/snmp: hardening: replace unbounded strcat with offset-tracked snprintf#21341somethingwithproof wants to merge 3 commits intophp:masterfrom
Conversation
|
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. |
a830ab1 to
6932afe
Compare
|
Updated commit subject and PR title to reflect hardening. |
ext/snmp/snmp.c
Outdated
| snprint_objid(buf2, sizeof(buf2), vars->name, vars->name_length); | ||
| if (rootlen <= vars->name_length && snmp_oid_compare(root, rootlen, vars->name, rootlen) == 0) { | ||
| buf2[0] = '\0'; | ||
| int pos = 0; |
There was a problem hiding this comment.
nit: I would rather see it as size_t type.
…rintf The suffix-as-keys code path in php_snmp builds a dotted OID suffix string by appending with strcat into a fixed 2048-byte buf2 array. The overflow is not reachable in practice: net-snmp's BER decoder enforces MAX_OID_LEN=128, and the worst-case suffix (128 subidentifiers at 11 bytes each) is 1408 bytes, within the buffer. Replace the strcat loop with direct snprintf into buf2 at a tracked size_t offset, breaking out of the loop if the buffer would be exhausted. Defense-in-depth against future net-snmp parser regressions. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
6932afe to
9b32d54
Compare
|
Fixed, squashed into the single commit. |
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
…check Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
|
This defensive programming change looks good to me. |
The suffix-as-keys code path in
php_snmpbuilds a dotted OID suffixstring by appending with
strcatinto a fixed 2048-bytebuf2array.The overflow is not reachable in practice: net-snmp's BER decoder
enforces
MAX_OID_LEN=128, and the worst-case suffix (128 subidentifiersat 11 bytes each) produces 1408 bytes, within the buffer.
Replace the
strcatloop with directsnprintfintobuf2at a trackedoffset, breaking out of the loop if the buffer would be exhausted.
Defense-in-depth against future net-snmp parser regressions.