From ff80f918fc2c20770ee2ffc70687ed4e260de9d6 Mon Sep 17 00:00:00 2001 From: Sergey Ivanov <seriv@cs.umd.edu> Date: Tue, 13 Jun 2017 12:58:08 -0400 Subject: [PATCH] Fix file handle comparison '==' can not compare file handles. We can use fileno() function to compare numerically file numbers. Code without this returns "connection successful" when it timeouts and $fd is "undefined". --- lib/Core/TcpService.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Core/TcpService.pm b/lib/Core/TcpService.pm index 30ed1b1..996a122 100644 --- a/lib/Core/TcpService.pm +++ b/lib/Core/TcpService.pm @@ -99,7 +99,7 @@ sub handler { connect($h, $s); $c->add($h); my ($fd) = $c->can_write($timeout); - if ($fd == $h) { + if (defined($fd) && (fileno($fd) == fileno($h))) { my $error = unpack("s", getsockopt($h, Socket::SOL_SOCKET, Socket::SO_ERROR)); if ($error != 0) { close($h); @@ -107,7 +107,7 @@ sub handler { } print $h $config->{'prepost'}."\r\n" if ($config->{'prepost'}); ($fd) = $c->can_read($timeout); - if ($fd == $h) { + if (defined($fd) && (fileno($fd) == fileno($h))) { chomp($banner = <$h>); print $h $config->{'post'} if ($config->{'post'}); close($h); -- GitLab