1
0
Эх сурвалжийг харах

Bug 610119 - fix coverify Defect Type: Null pointer dereferences issues 12167 - 12199

https://bugzilla.redhat.com/show_bug.cgi?id=610119
Resolves: bug 610119
Bug description: Fix coverify Defect Type: Null pointer dereferences issues 12167 - 12199
Fix description: Catch possible NULL pointer in stats_table_create_row().
Endi S. Dewata 15 жил өмнө
parent
commit
2ff2c9da76

+ 13 - 8
ldap/servers/snmp/ldap-agent.c

@@ -227,20 +227,25 @@ stats_table_create_row(unsigned long portnum)
     stats_table_context *ctx = SNMP_MALLOC_TYPEDEF(stats_table_context);
     oid *index_oid = (oid *)malloc(sizeof(oid) * MAX_OID_LEN);
 
+    if (!ctx || !index_oid) {
+        /* Error during malloc */
+        snmp_log(LOG_ERR, "malloc failed in stats_table_create_row\n");
+        goto error;
+    }
+
     /* Create index using port number */
     index_oid[0] = portnum;
     index.oids = index_oid;
     index.len = 1;
 
     /* Copy index into row structure */
-    if (ctx && index_oid) {
-        memcpy(&ctx->index, &index, sizeof(index));
-        return ctx;
-    } else {
-        /* Error during malloc */
-        snmp_log(LOG_ERR, "malloc failed in stats_table_create_row\n");
-        return NULL;
-    }
+    memcpy(&ctx->index, &index, sizeof(index));
+    return ctx;
+
+error:
+    if (index_oid) free(index_oid);
+    if (ctx) SNMP_FREE(ctx);
+    return NULL;
 }
 
 /************************************************************