TLSProxy/Proxy.pm: straighten inner loop termination logic.
authorAndy Polyakov <appro@openssl.org>
Thu, 12 Apr 2018 08:05:22 +0000 (10:05 +0200)
committerAndy Polyakov <appro@openssl.org>
Sat, 14 Apr 2018 18:00:04 +0000 (20:00 +0200)
Original condition was susceptible to race condition...

Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/5933)

util/perl/TLSProxy/Proxy.pm

index ea2c7a689e85cc51e48c0f161356fb71f04ff9c9..9e9764d401d929c4d61a8fca57f12b037fe7137a 100644 (file)
@@ -369,12 +369,14 @@ sub clientstart
     $fdset = IO::Select->new($server_sock, $client_sock);
     my @ready;
     my $ctr = 0;
+    my $sessionfile = $self->{sessionfile};
     local $SIG{PIPE} = "IGNORE";
-    while($fdset->count
-            && (!(TLSProxy::Message->end)
-                || (defined $self->sessionfile()
-                    && (-s $self->sessionfile()) == 0))
-            && $ctr < 10) {
+    while($fdset->count && $ctr < 10) {
+        if (defined($sessionfile)) {
+            # s_client got -ign_eof and won't be exiting voluntarily, so we
+            # look for data *and* check on session file...
+            last if TLSProxy::Message->success() && -s $sessionfile;
+        }
         if (!(@ready = $fdset->can_read(1))) {
             $ctr++;
             next;