Skip to content

Commit

Permalink
maybe fixes the "Bag arg length for Socket::unpack_sockaddr_in" crash
Browse files Browse the repository at this point in the history
  • Loading branch information
jkominek committed Jul 15, 2021
1 parent 46eac8f commit 9c1c860
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
7 changes: 6 additions & 1 deletion Connection.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
13 changes: 10 additions & 3 deletions pircd
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 9c1c860

Please sign in to comment.