Don't call setsockopt with an invalid fd
authorMatt Caswell <matt@openssl.org>
Tue, 29 May 2018 15:09:02 +0000 (16:09 +0100)
committerMatt Caswell <matt@openssl.org>
Thu, 31 May 2018 09:39:13 +0000 (10:39 +0100)
This is probably a "should not happen" scenario, but better check anyway.
Found by Coverity.

Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6373)

apps/s_time.c

index 5688f4f5fb46155c0b8bf3c1ea80ddc8b049df63..82d40a5a513246acf7e47642a4864bc6e489bed9 100644 (file)
@@ -389,11 +389,14 @@ static SSL *doConnection(SSL *scon, const char *host, SSL_CTX *ctx)
 #if defined(SOL_SOCKET) && defined(SO_LINGER)
     {
         struct linger no_linger;
+        int fd;
 
         no_linger.l_onoff  = 1;
         no_linger.l_linger = 0;
-        (void) setsockopt(SSL_get_fd(serverCon), SOL_SOCKET, SO_LINGER,
-                          (char*)&no_linger, sizeof(no_linger));
+        fd = SSL_get_fd(serverCon);
+        if (fd >= 0)
+            (void)setsockopt(fd, SOL_SOCKET, SO_LINGER, (char*)&no_linger,
+                             sizeof(no_linger));
     }
 #endif