[PATCH] Fix crash on missing arguments to getaddrinfo()

Niko Tyni ntyni at debian.org
Thu Nov 11 10:53:28 UTC 2010


Isolated from upstream version 0.18_001.
---
 lib/Socket/GetAddrInfo.xs |    2 +-
 t/01getaddrinfo.t         |   10 +++++++++-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/lib/Socket/GetAddrInfo.xs b/lib/Socket/GetAddrInfo.xs
index f6c0864..a786f96 100644
--- a/lib/Socket/GetAddrInfo.xs
+++ b/lib/Socket/GetAddrInfo.xs
@@ -111,7 +111,7 @@ BOOT:
   setup_constants();
 
 void
-getaddrinfo(host=NULL, service=NULL, hints=NULL)
+getaddrinfo(host=&PL_sv_undef, service=&PL_sv_undef, hints=NULL)
     SV   *host
     SV   *service
     SV   *hints
diff --git a/t/01getaddrinfo.t b/t/01getaddrinfo.t
index 3899712..d75c68c 100644
--- a/t/01getaddrinfo.t
+++ b/t/01getaddrinfo.t
@@ -2,7 +2,7 @@
 
 use strict;
 
-use Test::More tests => 28;
+use Test::More tests => 30;
 use Test::Exception;
 
 use Socket::GetAddrInfo qw( :newapi getaddrinfo AI_NUMERICHOST );
@@ -186,3 +186,11 @@ dies_ok( sub { getaddrinfo( "127.0.0.1", "80", "hints" ) },
          'getaddrinfo() with string hints dies' );
 dies_ok( sub { getaddrinfo( "127.0.0.1", "80", [] ) },
          'getaddrinfo() with ARRAY hints dies' );
+
+# Ensure it doesn't segfault if args are missing
+
+( $err, @res ) = getaddrinfo();
+ok( defined $err, '$err defined for getaddrinfo()' );
+
+( $err, @res ) = getaddrinfo( "127.0.0.1" );
+ok( defined $err, '$err defined for getaddrinfo("127.0.0.1")' );
-- 
1.7.2.3


--tKW2IUtsqtDRztdT--





More information about the pkg-perl-maintainers mailing list