From aafc3ac264e9e8b347ba6b3b3b487e94b03fe7ef Mon Sep 17 00:00:00 2001 From: Michael Rash Date: Thu, 9 May 2013 22:35:08 -0400 Subject: [PATCH] [server] setsockopt() nad fcntl() return value checking (found by Coverity) --- server/fwknopd.c | 7 ++++++- server/tcp_server.c | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/server/fwknopd.c b/server/fwknopd.c index fb91d55c..0225f24f 100644 --- a/server/fwknopd.c +++ b/server/fwknopd.c @@ -621,7 +621,12 @@ write_pid_file(fko_srv_options_t *opts) return -1; } - fcntl(op_fd, F_SETFD, FD_CLOEXEC); + if(fcntl(op_fd, F_SETFD, FD_CLOEXEC) == -1) + { + close(op_fd); + perror("Unexpected error from fcntl: "); + return -1; + } /* Attempt to lock the PID file. If we get an EWOULDBLOCK * error, another instance already has the lock. So we grab diff --git a/server/tcp_server.c b/server/tcp_server.c index 48f0f88c..d60bff5e 100644 --- a/server/tcp_server.c +++ b/server/tcp_server.c @@ -108,7 +108,12 @@ run_tcp_server(fko_srv_options_t *opts) /* So that we can re-bind to it without TIME_WAIT problems */ - setsockopt(s_sock, SOL_SOCKET, SO_REUSEADDR, &reuse_addr, sizeof(reuse_addr)); + if(setsockopt(s_sock, SOL_SOCKET, SO_REUSEADDR, &reuse_addr, sizeof(reuse_addr)) == -1) + { + log_msg(LOG_ERR, "run_tcp_server: setsockopt error: %s", + strerror(errno)); + exit(EXIT_FAILURE); + } /* Make our main socket non-blocking so we don't have to be stuck on * listening for incoming connections.