diff mbox series

[1/2] core: Fix CID 292193 argument cannot be negative

Message ID 20200409121255.24428-1-toertel@gmail.com
State Accepted
Headers show
Series [1/2] core: Fix CID 292193 argument cannot be negative | expand

Commit Message

Mark Jonas April 9, 2020, 12:12 p.m. UTC
Calling socket() can fail. In this case socket() returns -1. In this
case it does not make sense to continue and use a broken listenfd when
calling bind().

Signed-off-by: Mark Jonas <toertel@gmail.com>
---
 core/network_thread.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/core/network_thread.c b/core/network_thread.c
index 677ec3d..19d54b3 100644
--- a/core/network_thread.c
+++ b/core/network_thread.c
@@ -123,6 +123,9 @@  int listener_create(const char *path, int type)
 	if (listenfd == -1) {
 		TRACE("creating socket at %s", path);
 		listenfd = socket(AF_LOCAL, type, 0);
+		if (listenfd < 0) {
+			return -1;
+		}
 		unlink(path);
 		bzero(&servaddr, sizeof(servaddr));
 		servaddr.sun_family = AF_LOCAL;
@@ -142,7 +145,6 @@  int listener_create(const char *path, int type)
 			return -1;
 		}
 	return listenfd;
-
 }
 
 static void cleanum_msg_list(void)