From 7262fd7141bdae8ae15c3f625988a7f26463cdb5 Mon Sep 17 00:00:00 2001 From: GDR! Date: Tue, 7 Jul 2015 19:30:50 +0200 Subject: [PATCH] CID 122499 (#1 of 1): Unchecked return value from library (CHECKED_RETURN)2. check_return: Calling setsockopt(bind_sockfd, 1, 2, &yes, 4U) without checking return value. This library function may fail and return an error code. --- client.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/client.c b/client.c index bb667d4..6c9217e 100644 --- a/client.c +++ b/client.c @@ -44,6 +44,7 @@ int local_bind() int yes = 1; int flags; int gai_status; + int setsockopt_status; snprintf(port, 6, "%d", local_port); @@ -67,7 +68,14 @@ int local_bind() exit(1); } - setsockopt(bind_sockfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)); + setsockopt_status = setsockopt(bind_sockfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)); + if(setsockopt_status < 0) + { + log_printf(L_ERROR, "Could not set socket options: %s\n", + explain_setsockopt(bind_sockfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int))); + freeaddrinfo(res); + exit(1); + } /* Set O_NONBLOCK to make accept() non-blocking */ if (-1 == (flags = fcntl(bind_sockfd, F_GETFL, 0)))