Skip to contentSkip to conversation

vhost-user-scsi: avoid unlink(NULL) with fd passing

PATCH In review Stefan Hajnoczi 3 participants 3 messages May 16, 2022

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 vhost-user-scsi: avoid unlink(NULL) with fd passing

Commit 747421e949fc1eb3ba66b5fcccdb7ba051918241 ("Implements Backend Program conventions for vhost-user-scsi") introduced fd-passing support as part of implementing the vhost-user backend program conventions.

When fd passing is used the UNIX domain socket path is NULL and we must not call unlink(2).

The unlink(2) call is necessary when the listen socket, lsock, was created successfully since that means the UNIX domain socket is visible in the file system.

Fixes Coverity CID 1488353
Fixes 747421e949fc1eb3ba66b5fcccdb7ba051918241 ("Implements Backend Program conventions for vhost-user-scsi")
---
 contrib/vhost-user-scsi/vhost-user-scsi.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
contrib/vhost-user-scsi/vhost-user-scsi.c +4 -1
index b2c0f98253..9ef61cf5a7 100644
@@ -433,13 +433,16 @@ out:
     if (vdev_scsi) {
         g_main_loop_unref(vdev_scsi->loop);
         g_free(vdev_scsi);
-        unlink(opt_socket_path);
     }
     if (csock >= 0) {
         close(csock);
     }
     if (lsock >= 0) {
         close(lsock);
+
+        if (opt_socket_path) {
+            unlink(opt_socket_path);
+        }
     }
     g_free(opt_socket_path);
     g_free(iscsi_uri);
Signature · 1 line
2.36.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 12 lines · Stefan Hajnoczi

Commit 747421e949fc1eb3ba66b5fcccdb7ba051918241 ("Implements Backend Program conventions for vhost-user-scsi") introduced fd-passing support as part of implementing the vhost-user backend program conventions.

When fd passing is used the UNIX domain socket path is NULL and we must not call unlink(2).

The unlink(2) call is necessary when the listen socket, lsock, was created successfully since that means the UNIX domain socket is visible in the file system.

Quoted 7 lines
Fixes Coverity CID 1488353
Fixes 747421e949fc1eb3ba66b5fcccdb7ba051918241 ("Implements Backend Program conventions for vhost-user-scsi")
---
 contrib/vhost-user-scsi/vhost-user-scsi.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

thanks
-- PMM

Reviewed-by on v2 1/1
#2 lore raw
In reply to Stefan Hajnoczi
Quoted 7 lines · Stefan Hajnoczi

Commit 747421e949fc1eb3ba66b5fcccdb7ba051918241 ("Implements Backend Program conventions for vhost-user-scsi") introduced fd-passing support as part of implementing the vhost-user backend program conventions.

When fd passing is used the UNIX domain socket path is NULL and we must not call unlink(2).

Quoted 8 lines

The unlink(2) call is necessary when the listen socket, lsock, was created successfully since that means the UNIX domain socket is visible in the file system.

Fixes Coverity CID 1488353
Fixes 747421e949fc1eb3ba66b5fcccdb7ba051918241 ("Implements Backend Program conventions for vhost-user-scsi")

---

Quoted 28 lines
 contrib/vhost-user-scsi/vhost-user-scsi.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
contrib/vhost-user-scsi/vhost-user-scsi.c +4 -1
index b2c0f98253..9ef61cf5a7 100644
@@ -433,13 +433,16 @@ out:
     if (vdev_scsi) {
         g_main_loop_unref(vdev_scsi->loop);
         g_free(vdev_scsi);
-        unlink(opt_socket_path);
     }
     if (csock >= 0) {
         close(csock);
     }
     if (lsock >= 0) {
         close(lsock);
+
+        if (opt_socket_path) {
+            unlink(opt_socket_path);
+        }
     }
     g_free(opt_socket_path);
     g_free(iscsi_uri);
Signature · 1 line
2.36.1