From: Ruben Kerkhof Date: Fri, 4 Dec 2015 20:03:44 +0000 (+0100) Subject: madwifi: make code a little bit clearer X-Git-Tag: collectd-5.5.1~25^2~9 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=51f407eeaf373508098a06b9e352b7ed794d6335;p=collectd.git madwifi: make code a little bit clearer buf2 is initialized to zero, readlink will write at most sizeof(buf2) -1 bytes, so the trailing null should not be overwritten. Coverity doesn't see that, rewrite the code differently so it does. CID #38027 Signed-off-by: Florian Forster --- diff --git a/src/madwifi.c b/src/madwifi.c index 13301fff..7987378e 100644 --- a/src/madwifi.c +++ b/src/madwifi.c @@ -821,15 +821,16 @@ check_devname (const char *dev) if (dev[0] == '.') return 0; - + ssnprintf (buf, sizeof (buf), "/sys/class/net/%s/device/driver", dev); - buf[sizeof (buf) - 1] = 0; + buf[sizeof (buf) - 1] = '\0'; - memset (buf2, 0, sizeof (buf2)); i = readlink (buf, buf2, sizeof (buf2) - 1); if (i < 0) return 0; + buf2[i] = '\0'; + if (strstr (buf2, "/drivers/ath_") == NULL) return 0; return 1;