test/vsock fix: add missing check on socket creation
authorFilippo Storniolo <f.storniolo95@gmail.com>
Fri, 3 Nov 2023 17:55:49 +0000 (18:55 +0100)
committerDavid S. Miller <davem@davemloft.net>
Tue, 7 Nov 2023 22:27:07 +0000 (22:27 +0000)
Add check on socket() return value in vsock_listen()
and vsock_connect()

Co-developed-by: Luigi Leonardi <luigi.leonardi@outlook.com>
Signed-off-by: Luigi Leonardi <luigi.leonardi@outlook.com>
Signed-off-by: Filippo Storniolo <f.storniolo95@gmail.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
tools/testing/vsock/util.c

index 92336721321af7f1760c609d07db07e0a0bc65ce..698b0b44a2eeaff8ffff154eb2a75bc1d72c273c 100644 (file)
@@ -104,6 +104,10 @@ static int vsock_connect(unsigned int cid, unsigned int port, int type)
        control_expectln("LISTENING");
 
        fd = socket(AF_VSOCK, type, 0);
+       if (fd < 0) {
+               perror("socket");
+               exit(EXIT_FAILURE);
+       }
 
        timeout_begin(TIMEOUT);
        do {
@@ -158,6 +162,10 @@ static int vsock_accept(unsigned int cid, unsigned int port,
        int old_errno;
 
        fd = socket(AF_VSOCK, type, 0);
+       if (fd < 0) {
+               perror("socket");
+               exit(EXIT_FAILURE);
+       }
 
        if (bind(fd, &addr.sa, sizeof(addr.svm)) < 0) {
                perror("bind");