From: Dr. David von Oheimb Date: Sat, 22 May 2021 09:59:44 +0000 (+0200) Subject: apps/lib/s_socket.c and 80-test_cmp_http.t: Make ACCEPT port reporting more robust X-Git-Tag: openssl-3.0.0-beta1~325 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d357dd51cbea662792b0816f441718b7fb66bd49;p=thirdparty%2Fopenssl.git apps/lib/s_socket.c and 80-test_cmp_http.t: Make ACCEPT port reporting more robust Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/15417) --- diff --git a/apps/lib/s_socket.c b/apps/lib/s_socket.c index f543551bf13..fbe913e37a7 100644 --- a/apps/lib/s_socket.c +++ b/apps/lib/s_socket.c @@ -195,6 +195,8 @@ int report_server_accept(BIO *out, int asock, int with_address) { int success = 0; + if (BIO_printf(out, "ACCEPT") <= 0) + return 0; if (with_address) { union BIO_sock_info_u info; char *hostname = NULL; @@ -206,16 +208,17 @@ int report_server_accept(BIO *out, int asock, int with_address) && (service = BIO_ADDR_service_string(info.addr, 1)) != NULL && BIO_printf(out, strchr(hostname, ':') == NULL - ? /* IPv4 */ "ACCEPT %s:%s\n" - : /* IPv6 */ "ACCEPT [%s]:%s\n", + ? /* IPv4 */ " %s:%s\n" + : /* IPv6 */ " [%s]:%s\n", hostname, service) > 0) success = 1; + else + (void)BIO_printf(out, "unknown:error\n"); OPENSSL_free(hostname); OPENSSL_free(service); BIO_ADDR_free(info.addr); - } else { - (void)BIO_printf(out, "ACCEPT\n"); + } else if (BIO_printf(out, "\n") > 0) { success = 1; } (void)BIO_flush(out); diff --git a/test/recipes/80-test_cmp_http.t b/test/recipes/80-test_cmp_http.t index c74a5faf039..106f580636b 100644 --- a/test/recipes/80-test_cmp_http.t +++ b/test/recipes/80-test_cmp_http.t @@ -187,8 +187,7 @@ indir data_dir() => sub { if ($server_name eq "Mock") { indir "Mock" => sub { $pid = start_mock_server(""); - skip "Cannot start or find the started CMP mock server", - scalar @all_aspects unless $pid; + die "Cannot start or find the started CMP mock server" unless $pid; } } foreach my $aspect (@all_aspects) { @@ -275,20 +274,23 @@ sub start_mock_server { my $cmd = bldtop_dir($app) . " -config server.cnf $args"; print "Current directory is ".getcwd()."\n"; print "Launching mock server: $cmd\n"; + die "Invalid port: $server_port" unless $server_port =~ m/^\d+$/; my $pid = open($server_fh, "$cmd|") or die "Trying to $cmd"; print "Pid is: $pid\n"; - # Find out the actual server port - while (<$server_fh>) { - print; - s/\R$//; # Better chomp - next unless (/^ACCEPT\s.*:(\d+)$/); - $server_port = $1; - $server_tls = $1; - $kur_port = $1; - $pbm_port = $1; - last; + if ($server_port eq "0") { + # Find out the actual server port + while (<$server_fh>) { + print; + s/\R$//; # Better chomp + next unless (/^ACCEPT/); + $server_port = $server_tls = $kur_port = $pbm_port = $1 + if m/^ACCEPT\s.*?:(\d+)$/; + last; + } } - return $pid; + return $pid if $server_port =~ m/^(\d+)$/; + stop_mock_server($pid); + return 0; } sub stop_mock_server { diff --git a/test/recipes/80-test_cmp_http_data/Mock/server.cnf b/test/recipes/80-test_cmp_http_data/Mock/server.cnf index 24a6ebb9f62..633dc9230b5 100644 --- a/test/recipes/80-test_cmp_http_data/Mock/server.cnf +++ b/test/recipes/80-test_cmp_http_data/Mock/server.cnf @@ -1,7 +1,6 @@ [cmp] # mock server configuration -# port 0 means that a random available port will be used -port = 0 +port = 0 # 0 means that the server should choose a random available port srv_cert = server.crt srv_key = server.key srv_secret = pass:test diff --git a/test/recipes/80-test_cmp_http_data/Mock/test.cnf b/test/recipes/80-test_cmp_http_data/Mock/test.cnf index 8c8913b3c9a..87dd575a8aa 100644 --- a/test/recipes/80-test_cmp_http_data/Mock/test.cnf +++ b/test/recipes/80-test_cmp_http_data/Mock/test.cnf @@ -17,6 +17,7 @@ policies = certificatePolicies [Mock] # the built-in OpenSSL CMP mock server no_check_time = 1 server_host = 127.0.0.1 # localhost +# server_port = 0 means that the port is determined by the server server_port = 0 server_tls = $server_port server_cert = server.crt