Blame SOURCES/net-snmp-5.7.2-incomplete-parse.patch

b5ae06
1212408 - net-snmp: snmp_pdu_parse() incompletely parsed varBinds left in list of variables
b5ae06
1248412 - net-snmp: snmp_pdu_parse() incompletely parsed varBinds left in list of variables [rhel-7.1.z]
b5ae06
b5ae06
Backported from:
b5ae06
b5ae06
commit f23bcd3ac6ddee5d0a48f9703007ccc738914791
b5ae06
Author: Robert Story <rstory@localhost>
b5ae06
Date:   Sat Apr 11 18:49:02 2015 -0400
b5ae06
b5ae06
    CHANGES: BUG: #2615: Don't return incompletely parsed varbinds
b5ae06
b5ae06
b5ae06
diff -up net-snmp-5.5/snmplib/snmp_api.c.incomplete-parse net-snmp-5.5/snmplib/snmp_api.c
b5ae06
--- net-snmp-5.5/snmplib/snmp_api.c.incomplete-parse	2015-07-30 12:10:31.495801514 +0200
b5ae06
+++ net-snmp-5.5/snmplib/snmp_api.c	2015-07-30 12:11:43.087038548 +0200
b5ae06
@@ -4508,10 +4508,9 @@ snmp_pdu_parse(netsnmp_pdu *pdu, u_char
b5ae06
     u_char          type;
b5ae06
     u_char          msg_type;
b5ae06
     u_char         *var_val;
b5ae06
-    int             badtype = 0;
b5ae06
     size_t          len;
b5ae06
     size_t          four;
b5ae06
-    netsnmp_variable_list *vp = NULL;
b5ae06
+    netsnmp_variable_list *vp = NULL, *vplast = NULL;
b5ae06
     oid             objid[MAX_OID_LEN];
b5ae06
     u_char         *p;
b5ae06
 
b5ae06
@@ -4647,38 +4646,24 @@ snmp_pdu_parse(netsnmp_pdu *pdu, u_char
b5ae06
                               (ASN_SEQUENCE | ASN_CONSTRUCTOR),
b5ae06
                               "varbinds");
b5ae06
     if (data == NULL)
b5ae06
-        return -1;
b5ae06
+        goto fail;
b5ae06
 
b5ae06
     /*
b5ae06
      * get each varBind sequence 
b5ae06
      */
b5ae06
     while ((int) *length > 0) {
b5ae06
-        netsnmp_variable_list *vptemp;
b5ae06
-        vptemp = (netsnmp_variable_list *) malloc(sizeof(*vptemp));
b5ae06
-        if (NULL == vptemp) {
b5ae06
-            return -1;
b5ae06
-        }
b5ae06
-        if (NULL == vp) {
b5ae06
-            pdu->variables = vptemp;
b5ae06
-        } else {
b5ae06
-            vp->next_variable = vptemp;
b5ae06
-        }
b5ae06
-        vp = vptemp;
b5ae06
-
b5ae06
-        vp->next_variable = NULL;
b5ae06
-        vp->val.string = NULL;
b5ae06
+        vp = SNMP_MALLOC_TYPEDEF(netsnmp_variable_list);
b5ae06
+        if (NULL == vp)
b5ae06
+            goto fail;
b5ae06
+        
b5ae06
         vp->name_length = MAX_OID_LEN;
b5ae06
-        vp->name = NULL;
b5ae06
-        vp->index = 0;
b5ae06
-        vp->data = NULL;
b5ae06
-        vp->dataFreeHook = NULL;
b5ae06
         DEBUGDUMPSECTION("recv", "VarBind");
b5ae06
         data = snmp_parse_var_op(data, objid, &vp->name_length, &vp->type,
b5ae06
                                  &vp->val_len, &var_val, length);
b5ae06
         if (data == NULL)
b5ae06
-            return -1;
b5ae06
+            goto fail;
b5ae06
         if (snmp_set_var_objid(vp, objid, vp->name_length))
b5ae06
-            return -1;
b5ae06
+            goto fail;
b5ae06
 
b5ae06
         len = MAX_PACKET_LENGTH;
b5ae06
         DEBUGDUMPHEADER("recv", "Value");
b5ae06
@@ -4690,7 +4675,7 @@ snmp_pdu_parse(netsnmp_pdu *pdu, u_char
b5ae06
                           (long *) vp->val.integer,
b5ae06
                           sizeof(*vp->val.integer));
b5ae06
             if (!p)
b5ae06
-                return -1;
b5ae06
+                goto fail;
b5ae06
             break;
b5ae06
         case ASN_COUNTER:
b5ae06
         case ASN_GAUGE:
b5ae06
@@ -4702,7 +4687,7 @@ snmp_pdu_parse(netsnmp_pdu *pdu, u_char
b5ae06
                                    (u_long *) vp->val.integer,
b5ae06
                                    vp->val_len);
b5ae06
             if (!p)
b5ae06
-                return -1;
b5ae06
+                goto fail;
b5ae06
             break;
b5ae06
 #ifdef NETSNMP_WITH_OPAQUE_SPECIAL_TYPES
b5ae06
         case ASN_OPAQUE_COUNTER64:
b5ae06
@@ -4715,7 +4700,7 @@ snmp_pdu_parse(netsnmp_pdu *pdu, u_char
b5ae06
                                      (struct counter64 *) vp->val.
b5ae06
                                      counter64, vp->val_len);
b5ae06
             if (!p)
b5ae06
-                return -1;
b5ae06
+                goto fail;
b5ae06
             break;
b5ae06
 #ifdef NETSNMP_WITH_OPAQUE_SPECIAL_TYPES
b5ae06
         case ASN_OPAQUE_FLOAT:
b5ae06
@@ -4724,7 +4709,7 @@ snmp_pdu_parse(netsnmp_pdu *pdu, u_char
b5ae06
             p = asn_parse_float(var_val, &len, &vp->type,
b5ae06
                             vp->val.floatVal, vp->val_len);
b5ae06
             if (!p)
b5ae06
-                return -1;
b5ae06
+                goto fail;
b5ae06
             break;
b5ae06
         case ASN_OPAQUE_DOUBLE:
b5ae06
             vp->val.doubleVal = (double *) vp->buf;
b5ae06
@@ -4732,7 +4717,7 @@ snmp_pdu_parse(netsnmp_pdu *pdu, u_char
b5ae06
             p = asn_parse_double(var_val, &len, &vp->type,
b5ae06
                              vp->val.doubleVal, vp->val_len);
b5ae06
             if (!p)
b5ae06
-                return -1;
b5ae06
+                goto fail;
b5ae06
             break;
b5ae06
         case ASN_OPAQUE_I64:
b5ae06
             vp->val.counter64 = (struct counter64 *) vp->buf;
b5ae06
@@ -4742,12 +4727,12 @@ snmp_pdu_parse(netsnmp_pdu *pdu, u_char
b5ae06
                                    sizeof(*vp->val.counter64));
b5ae06
 
b5ae06
             if (!p)
b5ae06
-                return -1;
b5ae06
+                goto fail;
b5ae06
             break;
b5ae06
 #endif                          /* NETSNMP_WITH_OPAQUE_SPECIAL_TYPES */
b5ae06
         case ASN_IPADDRESS:
b5ae06
             if (vp->val_len != 4)
b5ae06
-                return -1;
b5ae06
+                goto fail;
b5ae06
             /* fallthrough */
b5ae06
         case ASN_OCTET_STR:
b5ae06
         case ASN_OPAQUE:
b5ae06
@@ -4758,22 +4743,22 @@ snmp_pdu_parse(netsnmp_pdu *pdu, u_char
b5ae06
                 vp->val.string = (u_char *) malloc(vp->val_len);
b5ae06
             }
b5ae06
             if (vp->val.string == NULL) {
b5ae06
-                return -1;
b5ae06
+                goto fail;
b5ae06
             }
b5ae06
             p = asn_parse_string(var_val, &len, &vp->type, vp->val.string,
b5ae06
                              &vp->val_len);
b5ae06
             if (!p)
b5ae06
-                return -1;
b5ae06
+                goto fail;
b5ae06
             break;
b5ae06
         case ASN_OBJECT_ID:
b5ae06
             vp->val_len = MAX_OID_LEN;
b5ae06
             p = asn_parse_objid(var_val, &len, &vp->type, objid, &vp->val_len);
b5ae06
             if (!p)
b5ae06
-                return -1;
b5ae06
+                goto fail;
b5ae06
             vp->val_len *= sizeof(oid);
b5ae06
             vp->val.objid = (oid *) malloc(vp->val_len);
b5ae06
             if (vp->val.objid == NULL) {
b5ae06
-                return -1;
b5ae06
+                goto fail;
b5ae06
             }
b5ae06
             memmove(vp->val.objid, objid, vp->val_len);
b5ae06
             break;
b5ae06
@@ -4785,21 +4770,38 @@ snmp_pdu_parse(netsnmp_pdu *pdu, u_char
b5ae06
         case ASN_BIT_STR:
b5ae06
             vp->val.bitstring = (u_char *) malloc(vp->val_len);
b5ae06
             if (vp->val.bitstring == NULL) {
b5ae06
-                return -1;
b5ae06
+                goto fail;
b5ae06
             }
b5ae06
             p = asn_parse_bitstring(var_val, &len, &vp->type,
b5ae06
                                 vp->val.bitstring, &vp->val_len);
b5ae06
             if (!p)
b5ae06
-                return -1;
b5ae06
+                goto fail;
b5ae06
             break;
b5ae06
         default:
b5ae06
             snmp_log(LOG_ERR, "bad type returned (%x)\n", vp->type);
b5ae06
-            badtype = -1;
b5ae06
+            goto fail;
b5ae06
             break;
b5ae06
         }
b5ae06
         DEBUGINDENTADD(-4);
b5ae06
+
b5ae06
+        if (NULL == vplast) {
b5ae06
+            pdu->variables = vp;
b5ae06
+        } else {
b5ae06
+            vplast->next_variable = vp;
b5ae06
+        }
b5ae06
+        vplast = vp;
b5ae06
+        vp = NULL;
b5ae06
+
b5ae06
     }
b5ae06
-    return badtype;
b5ae06
+    return 0;
b5ae06
+
b5ae06
+fail:
b5ae06
+    DEBUGMSGTL(("recv", "error while parsing VarBindList\n"));
b5ae06
+    /** if we were parsing a var, remove it from the pdu and free it */
b5ae06
+    if (vp)
b5ae06
+        snmp_free_var(vp);
b5ae06
+
b5ae06
+    return -1;
b5ae06
 }
b5ae06
 
b5ae06
 /*