From 97cf9b05fa1cdb8e4e7f60016aa95ae0e976e8c3 Mon Sep 17 00:00:00 2001 From: Richard Levitte Date: Wed, 2 Jun 2021 21:19:18 +0200 Subject: [PATCH] test/recipes/80-test_cmp_http.t: Don't trust $server_port in start_mock_server() Even if $server_port isn't touched, it's still a number coming from configuration. It's therefore not trustable as an indicator that the ACCEPT line delivered a port number or an error indication. $accept_msg is used instead to capture the port if there is one, and be a better indicator of error. Fixes #15557 Fixes #15571 Reviewed-by: David von Oheimb (Merged from https://github.com/openssl/openssl/pull/15580) --- test/recipes/80-test_cmp_http.t | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/test/recipes/80-test_cmp_http.t b/test/recipes/80-test_cmp_http.t index fbd7470ff0097..9c99226721ec4 100644 --- a/test/recipes/80-test_cmp_http.t +++ b/test/recipes/80-test_cmp_http.t @@ -276,19 +276,30 @@ sub start_mock_server { my $pid = open($server_fh, "$cmd|") or die "Trying to $cmd"; print "Pid is: $pid\n"; if ($server_port == 0) { + # Clear it first + $server_port = undef; + # 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+)$/; + + # $1 may be undefined, which is OK to assign to $server_port, + # as that gets detected further down. + /^ACCEPT\s.*:(\d+)$/; + $server_port = $1; + last; } + + unless (defined $server_port) { + stop_mock_server($pid); + return 0; + } } - return $pid if $server_port =~ m/^(\d+)$/; - stop_mock_server($pid); - return 0; + $server_tls = $kur_port = $pbm_port = $server_port; + return $pid; } sub stop_mock_server {