Blame SOURCES/net-snmp-5.8-asn-parse-nlength.patch

5ab818
From 92f0fe9e0dc3cf7ab6e8cc94d7962df83d0ddbec Mon Sep 17 00:00:00 2001
5ab818
From: Bart Van Assche <bvanassche@acm.org>
5ab818
Date: Mon, 4 Jan 2021 12:21:59 -0800
5ab818
Subject: [PATCH] libsnmp: Fix asn_parse_nlength()
5ab818
5ab818
Handle length zero correctly.
5ab818
5ab818
Fixes: https://github.com/net-snmp/net-snmp/issues/253
5ab818
Fixes: a9850f4445cf ("asn parse: add NULL checks, check length lengths")
5ab818
---
5ab818
 snmplib/asn1.c | 2 +-
5ab818
 1 file changed, 1 insertion(+), 1 deletion(-)
5ab818
5ab818
diff --git a/snmplib/asn1.c b/snmplib/asn1.c
5ab818
index e983500e7..33c272768 100644
5ab818
--- a/snmplib/asn1.c
5ab818
+++ b/snmplib/asn1.c
5ab818
@@ -345,7 +345,7 @@ asn_parse_nlength(u_char *pkt, size_t pkt_len, u_long *data_len)
5ab818
          * long length; first byte is length of length (after masking high bit)
5ab818
          */
5ab818
         len_len = (int) ((*pkt & ~0x80) + 1);
5ab818
-        if ((int) pkt_len <= len_len )
5ab818
+        if (pkt_len < len_len)
5ab818
             return NULL;           /* still too short for length and data */
5ab818
 
5ab818
         /* now we know we have enough data to parse length */
5ab818
From baef04f9c6fe0eb3ac74dd4d26a19264eeaf7fa1 Mon Sep 17 00:00:00 2001
5ab818
From: Bart Van Assche <bvanassche@acm.org>
5ab818
Date: Mon, 4 Jan 2021 10:00:33 -0800
5ab818
Subject: [PATCH] testing/fulltests/unit-tests/T105trap_parse_clib: Add this
5ab818
 test
5ab818
5ab818
Add a reproducer for the bug fixed by the previous patch.
5ab818
---
5ab818
 .../unit-tests/T105trap_parse_clib.c          | 41 +++++++++++++++++++
5ab818
 1 file changed, 41 insertions(+)
5ab818
 create mode 100644 testing/fulltests/unit-tests/T105trap_parse_clib.c
5ab818
5ab818
diff --git a/testing/fulltests/unit-tests/T105trap_parse_clib.c b/testing/fulltests/unit-tests/T105trap_parse_clib.c
5ab818
new file mode 100644
5ab818
index 000000000..5c21ccdc7
5ab818
--- /dev/null
5ab818
+++ b/testing/fulltests/unit-tests/T105trap_parse_clib.c
5ab818
@@ -0,0 +1,41 @@
5ab818
+/* HEADER Parsing of an SNMP trap with no varbinds */
5ab818
+netsnmp_pdu pdu;
5ab818
+int rc;
5ab818
+static u_char trap_pdu[] = {
5ab818
+    /* Sequence with length of 0x2d = 45 bytes. */
5ab818
+    [ 0] = 0x30, [ 1] = 0x82, [ 2] = 0x00, [ 3] = 0x2d,
5ab818
+    /* version = INTEGER 0 */
5ab818
+    [ 4] = 0x02, [ 5] = 0x01, [ 6] = 0x00,
5ab818
+    /* community = public (OCTET STRING 0x70 0x75 0x62 0x6c 0x69 0x63) */
5ab818
+    [ 7] = 0x04, [ 8] = 0x06, [ 9] = 0x70, [10] = 0x75,
5ab818
+    [11] = 0x62, [12] = 0x6c, [13] = 0x69, [14] = 0x63,
5ab818
+    /* SNMP_MSG_TRAP; 32 bytes. */
5ab818
+    [15] = 0xa4, [16] = 0x20,
5ab818
+    /* enterprise = OBJECT IDENTIFIER .1.3.6.1.6.3.1.1.5 = snmpTraps */
5ab818
+    [17] = 0x06, [18] = 0x08,
5ab818
+    [19] = 0x2b, [20] = 0x06, [21] = 0x01, [22] = 0x06,
5ab818
+    [23] = 0x03, [24] = 0x01, [25] = 0x01, [26] = 0x05,
5ab818
+    /* agent-addr = ASN_IPADDRESS 192.168.1.34 */
5ab818
+    [27] = 0x40, [28] = 0x04, [29] = 0xc0, [30] = 0xa8,
5ab818
+    [31] = 0x01, [32] = 0x22,
5ab818
+    /* generic-trap = INTEGER 0 */
5ab818
+    [33] = 0x02, [34] = 0x01, [35] = 0x00,
5ab818
+    /* specific-trap = INTEGER 0 */
5ab818
+    [36] = 0x02, [37] = 0x01, [38] = 0x00,
5ab818
+    /* ASN_TIMETICKS 0x117f243a */
5ab818
+    [39] = 0x43, [40] = 0x04, [41] = 0x11, [42] = 0x7f,
5ab818
+    [43] = 0x24, [44] = 0x3a,
5ab818
+    /* varbind list */
5ab818
+    [45] = 0x30, [46] = 0x82, [47] = 0x00, [48] = 0x00,
5ab818
+};
5ab818
+static size_t trap_pdu_length = sizeof(trap_pdu);
5ab818
+netsnmp_session session;
5ab818
+
5ab818
+snmp_set_do_debugging(TRUE);
5ab818
+debug_register_tokens("dumpv_recv,dumpv_send,asn,recv");
5ab818
+memset(&session, 0, sizeof(session));
5ab818
+snmp_sess_init(&session);
5ab818
+memset(&pdu, 0, sizeof(pdu));
5ab818
+rc = snmp_parse(NULL, &session, &pdu, trap_pdu, trap_pdu_length);
5ab818
+
5ab818
+OKF((rc == 0), ("Parsing of a trap PDU"));
5ab818