Skip to contentSkip to conversation

tests/vhost-user-bridge.c: Sanity check socket path length

PATCH In review Peter Maydell 2 participants 2 messages Sep 1, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests/vhost-user-bridge.c: Sanity check socket path length

The vhost-user-bridge binary accepts a UNIX socket path on the command line. Sanity check that this is short enough to fit into a sockaddr_un before copying it in.

Fixes Coverity CID 1432866
---
 tests/vhost-user-bridge.c | 5 +++++
 1 file changed, 5 insertions(+)
tests/vhost-user-bridge.c +5 -0
index 24815920b2b..cb009545fa5 100644
@@ -540,6 +540,11 @@ vubr_new(const char *path, bool client)
     CallbackFunc cb;
     size_t len;
 
+    if (strlen(path) >= sizeof(un.sun_path)) {
+        fprintf(stderr, "unix domain socket path '%s' is too long\n", path);
+        exit(1);
+    }
+
     /* Get a UNIX socket. */
     dev->sock = socket(AF_UNIX, SOCK_STREAM, 0);
     if (dev->sock == -1) {
Signature · 1 line
2.20.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Peter Maydell

The vhost-user-bridge binary accepts a UNIX socket path on the command line. Sanity check that this is short enough to fit into a sockaddr_un before copying it in.

Fixes Coverity CID 1432866

---

Quoted 25 lines
 tests/vhost-user-bridge.c | 5 +++++
 1 file changed, 5 insertions(+)
tests/vhost-user-bridge.c +5 -0
index 24815920b2b..cb009545fa5 100644
@@ -540,6 +540,11 @@ vubr_new(const char *path, bool client)
     CallbackFunc cb;
     size_t len;
 
+    if (strlen(path) >= sizeof(un.sun_path)) {
+        fprintf(stderr, "unix domain socket path '%s' is too long\n",
 path);
+        exit(1);
+    }
+
     /* Get a UNIX socket. */
     dev->sock = socket(AF_UNIX, SOCK_STREAM, 0);
     if (dev->sock == -1) {

--
2.20.1

Signature · 1 line
Marc-André Lureau