Permalink
Browse files

check return value from setsockopt

Coverity Scan defect 719425
  • Loading branch information...
1 parent a9d4367 commit f34790f4be661ce17489c5996805dd31fee883d0 @kr committed Sep 5, 2012
Showing with 24 additions and 4 deletions.
  1. +24 −4 net.c
View
@@ -74,10 +74,30 @@ make_server_socket(char *host, char *port)
}
flags = 1;
- setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &flags, sizeof flags);
- setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &flags, sizeof flags);
- setsockopt(fd, SOL_SOCKET, SO_LINGER, &linger, sizeof linger);
- setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &flags, sizeof flags);
+ r = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &flags, sizeof flags);
+ if (r == -1) {
+ twarn("setting SO_REUSEADDR on fd %d", fd);
+ close(fd);
+ continue;
+ }
+ r = setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &flags, sizeof flags);
+ if (r == -1) {
+ twarn("setting SO_KEEPALIVE on fd %d", fd);
+ close(fd);
+ continue;
+ }
+ r = setsockopt(fd, SOL_SOCKET, SO_LINGER, &linger, sizeof linger);
+ if (r == -1) {
+ twarn("setting SO_LINGER on fd %d", fd);
+ close(fd);
+ continue;
+ }
+ r = setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &flags, sizeof flags);
+ if (r == -1) {
+ twarn("setting TCP_NODELAY on fd %d", fd);
+ close(fd);
+ continue;
+ }
if (verbose) {
char hbuf[NI_MAXHOST], pbuf[NI_MAXSERV], *h = host, *p = port;

0 comments on commit f34790f

Please sign in to comment.