]> git.proxmox.com Git - mirror_qemu.git/commitdiff
virtfs-proxy-helper: fail gracefully if socket path is too long
authorStefan Hajnoczi <stefanha@redhat.com>
Mon, 30 Mar 2015 13:57:16 +0000 (14:57 +0100)
committerAneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Tue, 16 Jun 2015 15:02:29 +0000 (20:32 +0530)
Replace the assertion check with graceful failure when the socket path
is too long.  Programs should not crash on invalid input.  Print an
error message and exit properly.

Cc: Shannon Zhao <zhaoshenglong@huawei.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
fsdev/virtfs-proxy-helper.c

index 91e8b9b7f1cf8c00ef484122dbcb62520e1ef583..9097d15c989ca243a8a0c51ff61ae1f47ecc523b 100644 (file)
@@ -739,7 +739,12 @@ static int proxy_socket(const char *path, uid_t uid, gid_t gid)
         return -1;
     }
 
-    g_assert(strlen(path) < sizeof(proxy.sun_path));
+    if (strlen(path) >= sizeof(proxy.sun_path)) {
+        do_log(LOG_CRIT, "UNIX domain socket path exceeds %zu characters\n",
+               sizeof(proxy.sun_path));
+        return -1;
+    }
+
     sock = socket(AF_UNIX, SOCK_STREAM, 0);
     if (sock < 0) {
         do_perror("socket");