Skip to content

Commit

Permalink
CID 122499 (#1 of 1): Unchecked return value from library
Browse files Browse the repository at this point in the history
(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.
  • Loading branch information
gjedeer committed Jul 7, 2015
1 parent f1826d2 commit 7262fd7
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion client.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ int local_bind()
int yes = 1;
int flags;
int gai_status;
int setsockopt_status;

snprintf(port, 6, "%d", local_port);

Expand All @@ -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)))
Expand Down

0 comments on commit 7262fd7

Please sign in to comment.