summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: c144ae4)
raw | patch | inline | side by side (parent: c144ae4)
author | Florian Forster <octo@collectd.org> | |
Fri, 19 May 2017 13:10:46 +0000 (15:10 +0200) | ||
committer | Florian Forster <octo@collectd.org> | |
Fri, 19 May 2017 13:11:39 +0000 (15:11 +0200) |
src/snmp.c | patch | blob | history |
diff --git a/src/snmp.c b/src/snmp.c
index 8f6a1460f181335995822026b430a2fd08f11787..77349f62cc68e88d7c21b81a1c48c0d597dd324d 100644 (file)
--- a/src/snmp.c
+++ b/src/snmp.c
value_list_t vl = VALUE_LIST_INIT;
csnmp_list_instances_t *instance_list_ptr;
- csnmp_table_values_t **value_table_ptr;
+ csnmp_table_values_t *value_table_ptr[data->values_len];
size_t i;
_Bool have_more;
instance_list_ptr = instance_list;
- value_table_ptr = calloc(data->values_len, sizeof(*value_table_ptr));
- if (value_table_ptr == NULL)
- return -1;
for (i = 0; i < data->values_len; i++)
value_table_ptr[i] = value_table[i];
- vl.values_len = data->values_len;
- vl.values = malloc(sizeof(*vl.values) * vl.values_len);
- if (vl.values == NULL) {
- ERROR("snmp plugin: malloc failed.");
- sfree(value_table_ptr);
- return -1;
- }
-
sstrncpy(vl.host, host->name, sizeof(vl.host));
sstrncpy(vl.plugin, "snmp", sizeof(vl.plugin));
memcpy(¤t_suffix, &instance_list_ptr->suffix,
sizeof(current_suffix));
- } else /* no instance configured */
- {
+ } else {
+ /* no instance configured */
csnmp_table_values_t *ptr = value_table_ptr[0];
if (ptr == NULL) {
have_more = 0;
data->instance_prefix, temp);
}
+ vl.values_len = data->values_len;
+ value_t values[vl.values_len];
+ vl.values = values;
+
for (i = 0; i < data->values_len; i++)
vl.values[i] = value_table_ptr[i]->value;
if (vl.type_instance[0] != '\0')
plugin_dispatch_values(&vl);
+ /* prevent leakage of pointer to local variable. */
+ vl.values_len = 0;
+ vl.values = NULL;
+
if (instance_list != NULL)
instance_list_ptr = instance_list_ptr->next;
else
value_table_ptr[0] = value_table_ptr[0]->next;
} /* while (have_more) */
- sfree(vl.values);
- sfree(value_table_ptr);
-
- return 0;
+ return (0);
} /* int csnmp_dispatch_table */
static int csnmp_read_table(host_definition_t *host, data_definition_t *data) {