]> asedeno.scripts.mit.edu Git - PuTTY.git/commitdiff
Add an error check to every setsockopt call in uxnet.c.
authorSimon Tatham <anakin@pobox.com>
Fri, 19 Jul 2013 17:45:01 +0000 (17:45 +0000)
committerSimon Tatham <anakin@pobox.com>
Fri, 19 Jul 2013 17:45:01 +0000 (17:45 +0000)
[originally from svn r9939]

unix/uxnet.c

index fef4c43c132d50c4a28e5273c00c8d3d7a236577..e95152419fce9406663ed329aa700289e02ea7b2 100644 (file)
@@ -572,17 +572,32 @@ static int try_connect(Actual_Socket sock)
 
     if (sock->oobinline) {
        int b = TRUE;
-       setsockopt(s, SOL_SOCKET, SO_OOBINLINE, (void *) &b, sizeof(b));
+       if (setsockopt(s, SOL_SOCKET, SO_OOBINLINE,
+                       (void *) &b, sizeof(b)) < 0) {
+            err = errno;
+            close(s);
+            goto ret;
+        }
     }
 
     if (sock->nodelay) {
        int b = TRUE;
-       setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (void *) &b, sizeof(b));
+       if (setsockopt(s, IPPROTO_TCP, TCP_NODELAY,
+                       (void *) &b, sizeof(b)) < 0) {
+            err = errno;
+            close(s);
+            goto ret;
+        }
     }
 
     if (sock->keepalive) {
        int b = TRUE;
-       setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, (void *) &b, sizeof(b));
+       if (setsockopt(s, SOL_SOCKET, SO_KEEPALIVE,
+                       (void *) &b, sizeof(b)) < 0) {
+            err = errno;
+            close(s);
+            goto ret;
+        }
     }
 
     /*
@@ -835,7 +850,12 @@ Socket sk_newlistener(char *srcaddr, int port, Plug plug, int local_host_only, i
 
     ret->oobinline = 0;
 
-    setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (const char *)&on, sizeof(on));
+    if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR,
+                   (const char *)&on, sizeof(on)) < 0) {
+        ret->error = strerror(errno);
+        close(s);
+        return (Socket) ret;
+    }
 
     retcode = -1;
     addr = NULL; addrlen = -1;         /* placate optimiser */