Code

varnish plugin: Code cleanup:
authorFlorian Forster <octo@collectd.org>
Thu, 9 Nov 2017 15:18:33 +0000 (16:18 +0100)
committerFlorian Forster <octo@collectd.org>
Thu, 9 Nov 2017 15:18:33 +0000 (16:18 +0100)
*   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

index d105b025a62922f332a754403411f3d5e449956d..08260dc27fe5c28e2a7eb58c6b7350735aa9a827 100644 (file)
@@ -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