]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
s_socket.c: Avoid possible NULL pointer dereference
authorTomas Mraz <tomas@openssl.org>
Mon, 4 Oct 2021 09:19:33 +0000 (11:19 +0200)
committerTomas Mraz <tomas@openssl.org>
Wed, 6 Oct 2021 15:23:28 +0000 (17:23 +0200)
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
(Merged from https://github.com/openssl/openssl/pull/16736)

apps/lib/s_socket.c

index 4e262e681d69e39f7a0154982b6ea1ae0ff04825..805a1f0f3df4879d5759b7766ec57e6793b71475 100644 (file)
@@ -82,7 +82,6 @@ int init_client(int *sock, const char *host, const char *port,
     BIO_ADDRINFO *bindaddr = NULL;
     const BIO_ADDRINFO *ai = NULL;
     const BIO_ADDRINFO *bi = NULL;
-    char *hostname = NULL;
     int found = 0;
     int ret;
 
@@ -173,10 +172,6 @@ int init_client(int *sock, const char *host, const char *port,
         break;
     }
 
-    hostname = BIO_ADDR_hostname_string(BIO_ADDRINFO_address(ai), 1);
-    BIO_printf(bio_out, "Connecting to %s\n", hostname);
-    OPENSSL_free(hostname);
-
     if (*sock == INVALID_SOCKET) {
         if (bindaddr != NULL && !found) {
             BIO_printf(bio_err, "Can't bind %saddress for %s%s%s\n",
@@ -193,6 +188,13 @@ int init_client(int *sock, const char *host, const char *port,
         }
         ERR_print_errors(bio_err);
     } else {
+        char *hostname = NULL;
+
+        hostname = BIO_ADDR_hostname_string(BIO_ADDRINFO_address(ai), 1);
+        if (hostname != NULL) {
+            BIO_printf(bio_out, "Connecting to %s\n", hostname);
+            OPENSSL_free(hostname);
+        }
         /* Remove any stale errors from previous connection attempts */
         ERR_clear_error();
         ret = 1;