ASN.1 object identifiers are length-delimited, not null-terminated. If
the input encoding omits a terminating byte (MSB clear), then the parser
would walk past the buffer.
Also simplified expressions related to sub-identifier parsing.
while (length > 0 && (*objidlength)-- > 0) {
subidentifier = 0;
- do { /* shift and add in low order 7 bits */
+ do {
+ if (length-- <= 0) {
+ snmp_set_api_error(SNMPERR_ASN_DECODE);
+ return (NULL);
+ }
+ // shift and add in low order 7 bits
subidentifier = (subidentifier << 7)
- + (*(u_char *) bufp & ~ASN_BIT8);
- length--;
- } while (*(u_char *) bufp++ & ASN_BIT8);
+ | (*bufp & ~ASN_BIT8);
+ } while (*bufp++ & ASN_BIT8);
/* while last byte has high bit clear */
if (subidentifier > (u_int) MAX_SUBID) {