Bug#602832: libsocket-getaddrinfo-perl: Segfaults on lenny

gregor herrmann gregoa at debian.org
Mon Nov 8 17:14:19 UTC 2010


severity 602832 grave
retitle 602832 libsocket-getaddrinfo-perl: 0.16-1 segfaults on lenny and squeeze
fixed 602832 0.19-1
thanks

On Mon, 08 Nov 2010 16:25:44 +0000, Dominic Hargreaves wrote:

> I haven't checked on squeeze, but rebuilding this on lenny this
> module causes a segfault running the simple test script:

I installed 0.16-1 on a (mostly) squeeze system (perl and friends are
actually from unstable), and it segfaults too:

#v+
$ gdb perl
[..]
(gdb) run test.pl
Starting program: /usr/bin/perl test.pl
[Thread debugging using libthread_db enabled]

Program received signal SIGSEGV, Segmentation fault.
0xb7fdecf3 in XS_Socket__GetAddrInfo_getaddrinfo ()
   from /usr/lib/perl5/auto/Socket/GetAddrInfo/GetAddrInfo.so
(gdb) bt full
#0  0xb7fdecf3 in XS_Socket__GetAddrInfo_getaddrinfo ()
   from /usr/lib/perl5/auto/Socket/GetAddrInfo/GetAddrInfo.so
No symbol table info available.
#1  0x080d5d7b in Perl_pp_entersub ()
No symbol table info available.
#2  0x080d4358 in Perl_runops_standard ()
No symbol table info available.
#3  0x08079472 in perl_run ()
No symbol table info available.
#4  0x080642fd in main ()
No symbol table info available.
(gdb) 
#v-

Let's try with perl-debug:

#v+
$ gdb debugperl
[..]
(gdb) run test.pl
Starting program: /usr/bin/debugperl test.pl
[Thread debugging using libthread_db enabled]

Program received signal SIGSEGV, Segmentation fault.
0xb7fdecf3 in XS_Socket__GetAddrInfo_getaddrinfo ()
   from /usr/lib/perl5/auto/Socket/GetAddrInfo/GetAddrInfo.so
(gdb) bt full
#0  0xb7fdecf3 in XS_Socket__GetAddrInfo_getaddrinfo ()
   from /usr/lib/perl5/auto/Socket/GetAddrInfo/GetAddrInfo.so
No symbol table info available.
#1  0x08112976 in Perl_pp_entersub (my_perl=0x82a2008) at pp_hot.c:2891
        markix = <value optimized out>
        sp = <value optimized out>
        sv = 0x8315d2c
        gv = 0x2e352f6c
        cv = 0x830869c
        cx = <value optimized out>
        gimme = <value optimized out>
        hasargs = 1 '\001'
#2  0x080e2f68 in Perl_runops_debug (my_perl=0x82a2008) at dump.c:1968
No locals.
#3  0x08080cfc in S_run_body (my_perl=0x82a2008) at perl.c:2431
No locals.
#4  perl_run (my_perl=0x82a2008) at perl.c:2349
        oldscope = 1
        ret = <value optimized out>
        cur_env = {je_prev = 0x82a217c, je_buf = {{__jmpbuf = {-1208414220, 0, 0, -1073745160, 37363750, 
                -305039031}, __mask_was_saved = 0, __saved_mask = {__val = {3221222072, 3085861253, 
                  137012536, 0, 308, 136738400, 1, 134581008, 136970532, 136978440, 136992532, 136978980, 
                  3221222072, 135494959, 136978440, 136992532, 12, 136978440, 3085022856, 136978980, 
                  3221222136, 134769547, 136978440, 12, 7, 0, 0, 0, 0, 134770944, 136977208, 0}}}}, 
          je_ret = 0, je_mustcatch = 0 '\000'}
#5  0x08064455 in main (argc=2, argv=0xbffff3e4, env=0xbffff3f0) at perlmain.c:117
        exitstatus = <value optimized out>
(gdb) 
#v-


After installing 0.19-1 from unstable I get the expected dump.


Code changes between 0.16 and 0.19 (i.e. ignoring tests, docs, build
stuff, and windows-specific tweaks):

#v+
Index: lib/Socket/GetAddrInfo.xs
===================================================================
--- lib/Socket/GetAddrInfo.xs   (revision 60276)
+++ lib/Socket/GetAddrInfo.xs   (working copy)
@@ -111,7 +116,7 @@
   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
@@ -119,6 +124,7 @@
   PREINIT:
     char *hostname = NULL;
     char *servicename = NULL;
+    STRLEN len;
     struct addrinfo hints_s = { 0 };
     struct addrinfo *res;
     struct addrinfo *res_iter;
@@ -126,11 +132,19 @@
     int n_res;
 
   PPCODE:
-    if(SvOK(host) && SvCUR(host))
-      hostname = SvPV_nolen(host);
+    SvGETMAGIC(host);
+    if(SvOK(host)) {
+      hostname = SvPV_nomg(host, len);
+      if (!len)
+        hostname = NULL;
+    }
 
-    if(SvOK(service) && SvCUR(service))
-      servicename = SvPV_nolen(service);
+    SvGETMAGIC(service);
+    if(SvOK(service)) {
+      servicename = SvPV_nomg(service, len);
+      if (!len)
+        servicename = NULL;
+    }
 
     if(hints && SvOK(hints)) {
       HV *hintshash;
@@ -147,7 +161,7 @@
         hints_s.ai_family = SvIV(*valp);
       if((valp = hv_fetch(hintshash, "socktype", 8, 0)) != NULL)
         hints_s.ai_socktype = SvIV(*valp);
-      if((valp = hv_fetch(hintshash, "protocol", 5, 0)) != NULL)
+      if((valp = hv_fetch(hintshash, "protocol", 8, 0)) != NULL)
         hints_s.ai_protocol = SvIV(*valp);
     }
 
@@ -171,7 +185,7 @@
       if(res_iter->ai_canonname)
         hv_store(res_hv, "canonname", 9, newSVpv(res_iter->ai_canonname, 0), 0);
       else
-        hv_store(res_hv, "canonname", 9, &PL_sv_undef, 0);
+        hv_store(res_hv, "canonname", 9, newSV(0), 0);
 
       XPUSHs(sv_2mortal(newRV_noinc((SV*)res_hv)));
       n_res++;
#v-

Cheers,
gregor

-- 
 .''`.   http://info.comodo.priv.at/ -- GPG key IDs: 0x8649AA06, 0x00F3CFE4
 : :' :  Debian GNU/Linux user, admin, & developer - http://www.debian.org/
 `. `'   Member of VIBE!AT & SPI, fellow of Free Software Foundation Europe
   `-    NP: Bob Dylan: Not Dark Yet
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.alioth.debian.org/pipermail/pkg-perl-maintainers/attachments/20101108/a962975e/attachment-0001.pgp>


More information about the pkg-perl-maintainers mailing list