]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
test/recipes/80-test_cmp_http.t: Don't trust $server_port in start_mock_server()
authorRichard Levitte <levitte@openssl.org>
Wed, 2 Jun 2021 19:19:18 +0000 (21:19 +0200)
committerRichard Levitte <levitte@openssl.org>
Sun, 6 Jun 2021 05:34:44 +0000 (07:34 +0200)
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 <david.von.oheimb@siemens.com>
(Merged from https://github.com/openssl/openssl/pull/15580)

test/recipes/80-test_cmp_http.t

index fbd7470ff0097de0994a9d62f1307e535aa0e083..9c99226721ec4ebd4b77f97760676aa3a381fd56 100644 (file)
@@ -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 {