[NoCat] Patch: alarm-02.patch

Karl Gaissmaier karl.gaissmaier at kiz.uni-ulm.de
Tue, 29 Jul 2003 00:06:49 +0200


--------------Boundary-00=_DF9R47GP6V2W29NTNWN0
Content-Type: text/plain;
  charset="us-ascii"
Content-Transfer-Encoding: 8bit

Name:
	alarm-02.patch

Affected Files:
	lib/NoCat/Gateway.pm

Version: Patch against 0.82 or later

Severity:
	unimportant, works wihout applying this patch

Description:
	handling a new connection on the gateway port is guarded
	with a timeout to prevent DoS and lurking processes. The
	alarm handling is a little bit improved with this patch.

-- 
Karl Gaissmaier       KIZ/Infrastructure, University of Ulm, Germany
Email:karl.gaissmaier@kiz.uni-ulm.de           Service Group Network
--------------Boundary-00=_DF9R47GP6V2W29NTNWN0
Content-Type: text/x-diff;
  charset="us-ascii";
  name="alarm-02.patch"
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment; filename="alarm-02.patch"

diff -Naur NoCatAuth-nightly/lib/NoCat/Gateway.pm NoCatAuth-mod/lib/NoCat/Gateway.pm
--- NoCatAuth-nightly/lib/NoCat/Gateway.pm	Mon Mar 10 17:50:51 2003
+++ NoCatAuth-mod/lib/NoCat/Gateway.pm	Wed Jul 16 17:17:26 2003
@@ -278,20 +278,21 @@
 
     $self->log( 8, "Connection to " . $sock->sockhost . " from $peerhost" );
 
-    # Set the UNIX alarm clock.
-    alarm( $self->{HandleTimeout} ) if $self->{HandleTimeout};
-
     # Wrap the call to handle() in eval{}, so we catch the
     # exception when the alarm goes off.
     #
-    # Then turn the alarm off, Schuyler, you moron!
-    eval { 
+    eval {
+	# ALRM signal handler only for this eval block
+	local $SIG{ALRM} = sub {die "timeout in handling connection\n"};
+
+	# Set the UNIX alarm clock.
+	alarm( $self->{HandleTimeout} ) if $self->{HandleTimeout};
 	$self->handle( $peer );
-	alarm 0 if $self->{HandleTimeout};
+	alarm 0;
     };
 
     # Note the warning if the call to handle() threw an exception.
-    $self->log( 1, "$peerhost: $@" ) if $@;
+    $self->log( 1, "peer $peerhost: $@" ) if $@;
 }
 
 sub check_expired { 

--------------Boundary-00=_DF9R47GP6V2W29NTNWN0--