Skip to content

Commit bfada5a

Browse files
fstorniolodavem330
authored andcommitted
test/vsock fix: add missing check on socket creation
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>
1 parent 3a5cc90 commit bfada5a

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

tools/testing/vsock/util.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ static int vsock_connect(unsigned int cid, unsigned int port, int type)
104104
control_expectln("LISTENING");
105105

106106
fd = socket(AF_VSOCK, type, 0);
107+
if (fd < 0) {
108+
perror("socket");
109+
exit(EXIT_FAILURE);
110+
}
107111

108112
timeout_begin(TIMEOUT);
109113
do {
@@ -158,6 +162,10 @@ static int vsock_accept(unsigned int cid, unsigned int port,
158162
int old_errno;
159163

160164
fd = socket(AF_VSOCK, type, 0);
165+
if (fd < 0) {
166+
perror("socket");
167+
exit(EXIT_FAILURE);
168+
}
161169

162170
if (bind(fd, &addr.sa, sizeof(addr.svm)) < 0) {
163171
perror("bind");

0 commit comments

Comments
 (0)