vhost-user-scsi: avoid unlink(NULL) with fd passing
PATCH 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).
--- contrib/vhost-user-scsi/vhost-user-scsi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
contrib/vhost-user-scsi/vhost-user-scsi.c +3 -1
@@ -433,7 +433,9 @@ out:if (vdev_scsi) {g_main_loop_unref (vdev_scsi->loop);g_free (vdev_scsi); -unlink (opt_socket_path); +if (opt_socket_path) { +unlink (opt_socket_path); + } }if (csock >=0 ) {close (csock);
Signature · 1 line
2.35.1
Quoted 10 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).
Fixes Coverity CID 1488353Fixes 747421e949fc1eb3ba66b5fcccdb7ba051918241 ("Implements Backend Program conventions for vhost-user-scsi")Signed-off-by Stefan Hajnoczi <[email protected]>
Quoted 22 lines
--- contrib/vhost-user-scsi/vhost-user-scsi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)contrib/vhost-user-scsi/vhost-user-scsi.c +3
-1@@ -433,7 +433,9 @@ out:if (vdev_scsi) {g_main_loop_unref (vdev_scsi->loop);g_free (vdev_scsi); -unlink (opt_socket_path); +if (opt_socket_path) { +unlink (opt_socket_path); + } }if (csock >=0 ) {close (csock);Signature · 1 line
2.35.1
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 6 lines
Fixes Coverity CID 1488353Fixes 747421e949fc1eb3ba66b5fcccdb7ba051918241 ("Implements Backend Program conventions for vhost-user-scsi")Signed-off-by Stefan Hajnoczi <[email protected]>--- contrib/vhost-user-scsi/vhost-user-scsi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
Quoted 20 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).
Fixes Coverity CID 1488353Fixes 747421e949fc1eb3ba66b5fcccdb7ba051918241 ("Implements Backend Program conventions for vhost-user-scsi")Signed-off-by Stefan Hajnoczi <[email protected]>--- contrib/vhost-user-scsi/vhost-user-scsi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)contrib/vhost-user-scsi/vhost-user-scsi.c +0
-0
contrib/vhost-user-scsi/vhost-user-scsi.c out: · line 439
Quoted 8 lines
contrib/vhost-user-scsi/vhost-user-scsi.c +3
-1@@ -433,7 +433,9 @@ out:if (vdev_scsi) {g_main_loop_unref (vdev_scsi->loop);g_free (vdev_scsi); -unlink (opt_socket_path); +if (opt_socket_path) { +unlink (opt_socket_path); + } }
Shouldn't this check-and-unlink be one level up, outside the "if (vdev_scsi)" ? There are error exit paths which get us to the 'out:' label where we have called unix_sock_new() but not yet done the g_new0() of vdev_scsi(). The only thing that needs to be guarded by "if (vdev_scsi)" is the g_main_loop_unref() (the g_free of vdev_scsi itself could be inside or outside, since g_free(NULL) is a nop).
thanks
-- PMM
Quoted 38 lines · Peter Maydell
Quoted 20 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).
Fixes Coverity CID 1488353Fixes 747421e949fc1eb3ba66b5fcccdb7ba051918241 ("Implements Backend Program conventions for vhost-user-scsi")Signed-off-by Stefan Hajnoczi <[email protected]>--- contrib/vhost-user-scsi/vhost-user-scsi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)contrib/vhost-user-scsi/vhost-user-scsi.c +0
-0contrib/vhost-user-scsi/vhost-user-scsi.c out: · line 439
Quoted 8 lines
contrib/vhost-user-scsi/vhost-user-scsi.c +3
-1@@ -433,7 +433,9 @@ out:if (vdev_scsi) {g_main_loop_unref (vdev_scsi->loop);g_free (vdev_scsi); -unlink (opt_socket_path); +if (opt_socket_path) { +unlink (opt_socket_path); + } }Shouldn't this check-and-unlink be one level up, outside the "if (
vdev_scsi)" ? There are error exit paths which get us to the 'out:' label where we have calledunix_sock_new()but not yet done theg_new0()ofvdev_scsi(). The only thing that needs to be guarded by "if (vdev_scsi)" is theg_main_loop_unref()(theg_freeofvdev_scsiitself could be inside or outside, sinceg_free(NULL)is a nop).
Quoted 2 lines
thanks
-- PMM
Stefan, want to respond?
Signature · 1 line
MST
Quoted 30 lines · Peter Maydell
Quoted 20 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).
Fixes Coverity CID 1488353Fixes 747421e949fc1eb3ba66b5fcccdb7ba051918241 ("Implements Backend Program conventions for vhost-user-scsi")Signed-off-by Stefan Hajnoczi <[email protected]>--- contrib/vhost-user-scsi/vhost-user-scsi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)contrib/vhost-user-scsi/vhost-user-scsi.c +0
-0contrib/vhost-user-scsi/vhost-user-scsi.c out: · line 439
Quoted 8 lines
contrib/vhost-user-scsi/vhost-user-scsi.c +3
-1@@ -433,7 +433,9 @@ out:if (vdev_scsi) {g_main_loop_unref (vdev_scsi->loop);g_free (vdev_scsi); -unlink (opt_socket_path); +if (opt_socket_path) { +unlink (opt_socket_path); + } }
Quoted 7 lines
Shouldn't this check-and-unlink be one level up, outside the "if (
vdev_scsi)" ? There are error exit paths which get us to the 'out:' label where we have calledunix_sock_new()but not yet done theg_new0()ofvdev_scsi(). The only thing that needs to be guarded by "if (vdev_scsi)" is theg_main_loop_unref()(theg_freeofvdev_scsiitself could be inside or outside, sinceg_free(NULL)is a nop).
Sorry, I was offline last week due to illness. Now I'm back and agree with what you found. I have sent a v2.
Stefan