From c1e2bf3d2bfa1a1da3a6b42186577f635795e7f8 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Thu, 9 Nov 2017 16:18:33 +0100 Subject: [PATCH] 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(). --- src/varnish.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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 -- 2.30.2