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

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