From: Florian Forster Date: Thu, 9 Nov 2017 15:18:33 +0000 (+0100) Subject: varnish plugin: Code cleanup: X-Git-Tag: collectd-5.8.0~14^2 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=c1e2bf3d2bfa1a1da3a6b42186577f635795e7f8;p=collectd.git varnish plugin: Code cleanup: * Remove legacy rindex() with the POSIX strrchr(). * Check return value of strrchr(). * Chose non-arbitrary buffer size. * Use sstrncpy() instead of strcpy(). --- diff --git a/src/varnish.c b/src/varnish.c index d105b025..08260dc2 100644 --- a/src/varnish.c +++ b/src/varnish.c @@ -152,11 +152,13 @@ static int varnish_monitor(void *priv, conf = priv; #if HAVE_VARNISH_V5 - char namebuff[100]; - char *c; + char namebuff[DATA_MAX_NAME_LEN]; - c = rindex(pt->name, '.'); - strcpy(namebuff, c + 1); + char const *c = strrchr(pt->name, '.'); + if (c == NULL) { + return EINVAL; + } + sstrncpy(namebuff, c + 1, sizeof(namebuff)); name = namebuff; #elif HAVE_VARNISH_V4