Some changes to SslClient.pm in sslpoe:

Remove reference to $socket from %Filenum_Object.
Reason: It was keeping the tied filehandle from being DESTROYed.

In the READ method: Change "die ("handshake failed");"
to $! = 104; return undef.
Reason: This makes POE handle it like a normal
error. Dying allowed someone to send garbage via netcat
and crash the program, thus adding a DoS to any server that
uses SSL. That's not good.

However, errno 104 is "Connection reset by peer", and this is a lie.
Really the handshake failed... Perhaps some other value should be used for $!.


Added a DESTROY method that calls CLOSE,
as CLOSE is not called otherwise.

The patch is attached. These changes are pretty trivial, and further
work needs to be done on SslClient.pm to make it more robust. Also
perhaps it should properly be named "SSLSocketWraper" or somesuch?
The name is most confusing.
--- poe-ssl-sockets/SslClient.pm        2004-01-20 10:56:59.000000000 -0500
+++ poe-ssl-sockets-new/SslClient.pm    2004-08-21 16:08:10.000000000 -0400
@@ -31,7 +31,9 @@
   $Filenum_Object{$fileno} =
   { ssl    => $ssl,
     ctx    => $ctx,
-    socket => $socket,
+    # commented out $socket, because this caused a lot
+    # of problems.
+    #socket => $socket,
     fileno => $fileno,
     _is_accepted => $accepted,
   };
@@ -97,7 +99,9 @@
        return $$len;
       }
       else {
-       die ("handshake failed");
+                 #die ("handshake failed");
+                 $! = 104;
+                 return undef;
       }
     }
     $self->{_is_accepted} = 1;
@@ -136,6 +140,7 @@
        return 0;
       }
       else {
+       # Erm, perhaps it is better to return undef and set $! to errno?
        die "handshake failed: $errno";
       }
     }
@@ -154,6 +159,7 @@
 sub CLOSE {
   my $socket = shift;
   my $fileno = fileno($socket);
+  return unless exists $Filenum_Object{$fileno};
   my $self = $socket->_get_self();
   delete $Filenum_Object{$fileno};
   Net::SSLeay::free ($self->{ssl});
@@ -161,6 +167,10 @@
   close $socket;
 }
 
+sub DESTROY {
+       shift->CLOSE;
+}
+
 1;
 
 __END__

Reply via email to