Skip to content

Commit 2eb5203

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 b62bf24 commit 2eb5203

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
@@ -756,7 +756,7 @@ asn1_print(netdissect_options *ndo,
756756
}
757757

758758
for (; i != 0; p++, i--) {
759-
o = (o << ASN_SHIFT7) + (GET_U_1(p) & ~ASN_BIT8);
759+
o = ( ( o & 0x01ffffff ) << ASN_SHIFT7) + (GET_U_1(p) & ~ASN_BIT8);
760760
if (GET_U_1(p) & ASN_LONGLEN)
761761
continue;
762762

@@ -906,7 +906,7 @@ smi_decode_oid(netdissect_options *ndo,
906906
unsigned int firstval;
907907

908908
for (*oidlen = 0; i != 0; p++, i--) {
909-
o = (o << ASN_SHIFT7) + (GET_U_1(p) & ~ASN_BIT8);
909+
o = ( ( o & 0x01ffffff ) << ASN_SHIFT7) + (GET_U_1(p) & ~ASN_BIT8);
910910
if (GET_U_1(p) & ASN_LONGLEN)
911911
continue;
912912

0 commit comments

Comments
 (0)