From 4b396ba5395402488a8fddacd361836a6b5afdd5 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Thu, 18 Jun 2015 15:27:54 +0200 Subject: [PATCH] Fix "Undefined allocation of 0 bytes (CERT MEM04-C; CWE-131)" warnings. --- src/snmp.c | 1 + src/utils_db_query.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/snmp.c b/src/snmp.c index 3dd08e4a..4dd1d10c 100644 --- a/src/snmp.c +++ b/src/snmp.c @@ -1241,6 +1241,7 @@ static int csnmp_read_table (host_definition_t *host, data_definition_t *data) data->type, ds->ds_num, data->values_len); return (-1); } + assert (data->values_len > 0); /* We need a copy of all the OIDs, because GETNEXT will destroy them. */ memcpy (oid_list, data->values, data->values_len * sizeof (oid_t)); diff --git a/src/utils_db_query.c b/src/utils_db_query.c index ab4299b3..e8d7b3aa 100644 --- a/src/utils_db_query.c +++ b/src/utils_db_query.c @@ -192,8 +192,9 @@ static int udb_result_submit (udb_result_t *r, /* {{{ */ assert (r != NULL); assert (r_area->ds != NULL); assert (((size_t) r_area->ds->ds_num) == r->values_num); + assert (r->values_num > 0); - vl.values = (value_t *) calloc (r_area->ds->ds_num, sizeof (value_t)); + vl.values = (value_t *) calloc (r->values_num, sizeof (value_t)); if (vl.values == NULL) { ERROR ("db query utils: malloc failed."); -- 2.11.0