From fd4f771b65e8f23b50fa45f357f0d9e181c82b84 Mon Sep 17 00:00:00 2001 From: Petter Reinholdtsen Date: Sun, 2 Dec 2007 17:24:58 +0000 Subject: * Prefer REMOTE_ADDR over the output from gethostbyaddr() in get_peername, to avoid "Bad arg length" problem. --- debian/changelog | 7 +++++++ sitesummary-collector.cgi | 11 +++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/debian/changelog b/debian/changelog index 08f6c16..0c69423 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +sitesummary (0.0.34) UNRELEASED; urgency=low + + * Prefer REMOTE_ADDR over the output from gethostbyaddr() in + get_peername, to avoid "Bad arg length" problem. + + -- Petter Reinholdtsen Sun, 2 Dec 2007 18:23:51 +0100 + sitesummary (0.0.33) unstable; urgency=low * Collect loaded kernel modules, to ease nagios autoconfiguration. diff --git a/sitesummary-collector.cgi b/sitesummary-collector.cgi index 68ab091..199f4cc 100644 --- a/sitesummary-collector.cgi +++ b/sitesummary-collector.cgi @@ -144,16 +144,15 @@ sub get_peerinfo { my $sockethandle = shift; my ($peeripaddr, $peername) = ("", ""); - my $sockaddr = getpeername($sockethandle); - if ($sockaddr) { - my $peerport; - ($peerport, $peeripaddr) = sockaddr_in($sockaddr); - $peername = gethostbyaddr($peeripaddr, AF_INET); - } elsif ($ENV{'REMOTE_ADDR'}) { # CGI variable + if ($ENV{'REMOTE_ADDR'}) { # CGI variable $peeripaddr = $ENV{'REMOTE_ADDR'}; $peeripaddr =~ m/(\d+).(\d+).(\d+).(\d+)/; # Untaint $peeripaddr = "$1.$2.$3.$4"; $peername = gethostbyaddr($peeripaddr, AF_INET); + } elsif (my $sockaddr = getpeername($sockethandle)) { + my $peerport; + ($peerport, $peeripaddr) = sockaddr_in($sockaddr); + $peername = gethostbyaddr($peeripaddr, AF_INET); } else { # Running on the command line, use test host $peeripaddr = "127.0.0.1"; -- cgit v1.2.3