Skip to content

Commit 7f180e4

Browse files
committed
Avoid undefined behavior when decoding OID values in print-snmp
When decoding an OID, and shifting left by 7, mask off the top 7 bits first. This still results in GIGO, but avoids undefined behavior on the way there. OIDs with values this large are not supported by this code.
1 parent 7b1e0b2 commit 7f180e4

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

print-snmp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ asn1_print(netdissect_options *ndo,
753753
}
754754

755755
for (; i != 0; p++, i--) {
756-
o = (o << ASN_SHIFT7) + (GET_U_1(p) & ~ASN_BIT8);
756+
o = ( ( o & 0x01ffffff ) << ASN_SHIFT7) + (GET_U_1(p) & ~ASN_BIT8);
757757
if (GET_U_1(p) & ASN_LONGLEN)
758758
continue;
759759

@@ -903,7 +903,7 @@ smi_decode_oid(netdissect_options *ndo,
903903
unsigned int firstval;
904904

905905
for (*oidlen = 0; i != 0; p++, i--) {
906-
o = (o << ASN_SHIFT7) + (GET_U_1(p) & ~ASN_BIT8);
906+
o = ( ( o & 0x01ffffff ) << ASN_SHIFT7) + (GET_U_1(p) & ~ASN_BIT8);
907907
if (GET_U_1(p) & ASN_LONGLEN)
908908
continue;
909909

0 commit comments

Comments
 (0)