From 9c1c860553e49ca7885627e0ab6de7d0b7d9820c Mon Sep 17 00:00:00 2001 From: Jay Kominek Date: Thu, 15 Jul 2021 14:28:12 +0000 Subject: [PATCH] maybe fixes the "Bag arg length for Socket::unpack_sockaddr_in" crash --- Connection.pm | 7 ++++++- pircd | 13 ++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Connection.pm b/Connection.pm index 578411d..33493cd 100644 --- a/Connection.pm +++ b/Connection.pm @@ -30,7 +30,12 @@ sub new { $this->{'ssl'} = $this->{'socket'}->isa("IO::Socket::SSL"); - my($port,$iaddr) = sockaddr_in(getpeername($this->{'socket'})); + #my $port = $this->{'socket'}->peerport(); + my $iaddr = $this->{'socket'}->peeraddr(); + if(length($iaddr)!=4) { + print "got zero-length iaddr\n"; + return undef; + } $this->{'host'} = gethostbyaddr($iaddr,AF_INET) || inet_ntoa($iaddr); $this->{'host_ip'} = inet_ntoa($iaddr); diff --git a/pircd b/pircd index 535b5c3..2b10ffa 100755 --- a/pircd +++ b/pircd @@ -139,9 +139,16 @@ for(;;) { $client = $client->accept or next; $select->add($client); &setnonblocking($client); - $connections{$client} = Connection->new($client, \%outbuffer, - $Utils::thisserver); - $unfinished{$client} = $connections{$client}; + # new connection construction can fail + my $newconn = Connection->new($client, \%outbuffer, + $Utils::thisserver); + if(defined($newconn)) { + $connections{$client} = $newconn; + $unfinished{$client} = $newconn; + } else { + $select->remove($client); + close($client); + } } elsif(defined($connections{$client})) { # It is not the listening socket, so it is probably a client $time = time();