misc: vppctl - fix coverity warning 26/34526/6
authorKlement Sekera <ksekera@cisco.com>
Tue, 16 Nov 2021 11:19:26 +0000 (12:19 +0100)
committerAndrew Yourtchenko <ayourtch@gmail.com>
Fri, 28 Jan 2022 14:36:39 +0000 (14:36 +0000)
Check that provided path fits into defined buffer. Don't write too many
bytes to avoid having an unterminated string.

Type: fix
Fixes: 31f192434660
Signed-off-by: Klement Sekera <ksekera@cisco.com>
Change-Id: I1ea8b6d6a3474c032e542b6980ed14bac72093a8

src/vpp/app/vppctl.c

index c9f33ab..de5572d 100644 (file)
@@ -192,6 +192,13 @@ main (int argc, char *argv[])
 
   struct sockaddr_un saddr = { 0 };
   saddr.sun_family = AF_UNIX;
+
+  if (strlen (sock_fname) > sizeof (saddr.sun_path) - 1)
+    {
+      perror ("socket path too long");
+      exit (1);
+    }
+
   strncpy (saddr.sun_path, sock_fname, sizeof (saddr.sun_path) - 1);
 
   sock_fd = socket (AF_UNIX, SOCK_STREAM, 0);