apps/s_socket.c: fix memory sanitizer problem in ACCEPT printout.
[openssl.git] / apps / s_socket.c
index ae62a135ce8573e65db368211b2b03b1d811d251..69f0f4f05e7f9242ca725cf1fd368e74ae67f8b4 100644 (file)
@@ -211,7 +211,7 @@ int do_server(int *accept_sock, const char *host, const char *port,
     int i;
     BIO_ADDRINFO *res = NULL;
     const BIO_ADDRINFO *next;
-    int sock_family, sock_type, sock_protocol;
+    int sock_family, sock_type, sock_protocol, sock_port;
     const BIO_ADDR *sock_address;
     int sock_options = BIO_SOCK_REUSEADDR;
     int ret = 0;
@@ -280,10 +280,13 @@ int do_server(int *accept_sock, const char *host, const char *port,
     }
 #endif
 
+    sock_port = BIO_ADDR_rawport(sock_address);
+
     BIO_ADDRINFO_free(res);
     res = NULL;
 
-    {
+    if (sock_port == 0) {
+        /* dynamically allocated port, report which one */
         union BIO_sock_info_u info;
         char *hostname = NULL;
         char *service = NULL;
@@ -309,6 +312,9 @@ int do_server(int *accept_sock, const char *host, const char *port,
             ERR_print_errors(bio_err);
             goto end;
         }
+    } else {
+        (void)BIO_printf(bio_s_out, "ACCEPT\n");
+        (void)BIO_flush(bio_s_out);
     }
 
     if (accept_sock != NULL)