[server] setsockopt() nad fcntl() return value checking (found by Coverity)
authorMichael Rash <mbr@cipherdyne.org>
Fri, 10 May 2013 02:35:08 +0000 (22:35 -0400)
committerMichael Rash <mbr@cipherdyne.org>
Fri, 10 May 2013 02:35:08 +0000 (22:35 -0400)
server/fwknopd.c
server/tcp_server.c

index fb91d55..0225f24 100644 (file)
@@ -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
index 48f0f88..d60bff5 100644 (file)
@@ -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.