From: Florian Forster Date: Wed, 27 Aug 2008 10:08:33 +0000 (+0200) Subject: snmp plugin: Fix an off by one error. X-Git-Tag: collectd-4.5.0~17 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=c9a388f97676477d05b4bbc8b56bbdaed76c52b1;p=collectd.git snmp plugin: Fix an off by one error. The last character of an table instance was truncated. Fortunately empty strings were caught, so that uninitialized memory was never accessed. This patch also reverts f782b378: If returning with an error when a string is empty causes the entire read to fail. --- diff --git a/src/snmp.c b/src/snmp.c index 0dad67c8..877aafe9 100644 --- a/src/snmp.c +++ b/src/snmp.c @@ -859,22 +859,15 @@ static int csnmp_instance_list_add (csnmp_list_instances_t **head, char *ptr; size_t instance_len; + memset (il->instance, 0, sizeof (il->instance)); instance_len = sizeof (il->instance) - 1; if (instance_len > vb->val_len) instance_len = vb->val_len; - if (instance_len < 1) - { - ERROR ("snmp plugin: csnmp_instance_list_add: instance_len = %zu, " - "which is less than one.", instance_len); - sfree (il); - return (-1); - } - sstrncpy (il->instance, (char *) ((vb->type == ASN_OCTET_STR) ? vb->val.string : vb->val.bitstring), - instance_len); + instance_len + 1); for (ptr = il->instance; *ptr != '\0'; ptr++) {