develooper Front page | perl.perl5.porters | Postings from July 2018

Re: [perl #133391] Bad "Use of uninitialized value within @socks inref-to-glob cast"

Thread Previous
From:
Tom Molesworth via perl5-porters
Date:
July 18, 2018 10:43
Subject:
Re: [perl #133391] Bad "Use of uninitialized value within @socks inref-to-glob cast"
Message ID:
CAGXhHd=qmEe+G4oURm7GngF97VqLCeuZpimb2+sajZjA4s6gvA@mail.gmail.com
You have a 1-in-10 random condition within the first 'unless' clause, so
$socks[$i] is not guaranteed to be defined.

Also, probably better to pick a different name than 'x' for that function,
makes the test case a bit hard to read!


On Wed, 18 Jul 2018, 5:35 pm Ulrich Windl (via RT), <
perlbug-followup@perl.org> wrote:

> # New Ticket Created by  "Ulrich Windl"
> # Please include the string:  [perl #133391]
> # in the subject line of all future correspondence about this issue.
> # <URL: https://rt.perl.org/Ticket/Display.html?id=133391 >
>
>
> This is a bug report for perl from Ulrich.Windl@rz.uni-regensburg.de,
> generated with the help of perlbug 1.36 running under perl 5.10.0.
>
>
> -----------------------------------------------------------------
> I wrote a simple test program to send some random UDP packets to a
> specific address, simulating multiple senders, like this:
>
> ---
> require 5.010;
> use strict;
>
> use Socket;
>
> sub x($$)
> {
>     my ($addr, $proto) = @_;
>     my $socket;
>
>     $proto = (getprotobyname($proto))[2];
>     die unless ($proto);
>     if (socket($socket, PF_INET, SOCK_DGRAM, $proto)) {
>         my $port = 0;
>         my $my_addr = sockaddr_in($port, $addr);
>         unless (bind($socket, $my_addr)) {
>             my ($l_port, $l_addr) = sockaddr_in(getsockname($socket));
>             die sprintf("bind socket to address %s port %u: %s",
>                         inet_ntoa($l_addr), $l_port, $!);
>         }
>     } else {
>         print "socket(): $!\n";
>     }
>     return $socket;
> }
>
> my @socks;
> my $d_naddr = inet_aton('some_local_host_name');
> my $d_taddr = sockaddr_in(10123, $d_naddr);
>
> $#socks = 9;
> while (1) {
>     my $i = int(rand(10));
>     my $msg = ('A'..'Z', '0'..'9')[rand(36)] x rand(50);
>     print "sock $i\n";
>     unless ($socks[$i] || int(rand(10)) == 0) {
>         if (my $s = x($d_naddr, 'udp')) {
>             if ($socks[$i]) {
>                 print "close sock $i\n";
>                 close($socks[$i]) or die $!;
>             }
>             $socks[$i] = $s;
>             print "new sock $i\n";
>         } else {
>             print "new sock $i failed: $!\n";
>             next unless ($socks[$i]);
>             print "old sock $i\n";
>         }
>     }
>     print "msg $msg\n";
>     unless (send($socks[$i], $msg, 0, $d_taddr)) {
>         print "send(): $!\n";
>     }
>     sleep(3);
> }
> ---
>
> However I see errors I (and strace) cannot explain. Like this (partial
> strace):
>
> ---
> sock 9
> socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP) = 3
> bind(3, {sa_family=AF_INET, sin_port=htons(0),
> sin_addr=inet_addr("172.20.16.35")}, 16) = 0
> new sock 9
> msg 777777777777777777777
> sendto(3, "777777777777777777777", 21, 0, {sa_family=AF_INET,
> sin_port=htons(10123), sin_addr=inet_addr("172.20.16.35")}, 16) = 21
> sock 0
> msg KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK
> Use of uninitialized value within @socks in ref-to-glob cast at ./
> tester.pl line 64.
> Use of uninitialized value within @socks in ref-to-glob cast at ./
> tester.pl line 64.
> send() on unopened socket at ./tester.pl line 64.
> send(): Bad file descriptor
> ---
>
> So the socket to use is 3, and the send seems successful. Sometimes it
> takes
> quite some time until this error appears. For example:
>
> ---
> sock 6
> new sock 6
> msg 4444444444444444
> sock 3
> new sock 3
> msg
> send():
> sock 9
> new sock 9
> msg SSSSSSSSSSS
> sock 1
> new sock 1
> msg GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG
> sock 4
> new sock 4
> msg WWWWWWWWWWWWWWWWWWWWWWW
> sock 0
> new sock 0
> msg JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
> sock 8
> new sock 8
> msg GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG
> sock 5
> new sock 5
> msg JJJJJJJJJJJJJ
> sock 2
> new sock 2
> msg AAAAAAAAAAAAAAAA
> sock 0
> msg UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU
> sock 5
> msg TTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
> sock 9
> msg HHHHHHHHHHHHHHHHHHHHHHH
> sock 0
> msg LLLLLLLLLLLLLLLLLLLLLLLLLLL
> sock 3
> msg NNNNNNNNNNN
> sock 8
> msg VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
> sock 7
> msg QQQQQQQQ
> Use of uninitialized value within @socks in ref-to-glob cast at ./
> tester.pl line 64.
> Use of uninitialized value within @socks in ref-to-glob cast at ./
> tester.pl line 64.
> send() on unopened socket at ./tester.pl line 64.
> send(): Bad file descriptor
> sock 1
> msg 7
> sock 4
> msg VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
> ^C
> ---
>
> Thus I suspect some obscure error in the Socket module...
> Maybe I should add for completeness that the packets being sent are
> expected to be returned to the same socket, but I'm not receiving those
> yet...
>
>
> [Please do not change anything below this line]
> -----------------------------------------------------------------
> ---
> Flags:
>     category=library
>     severity=medium
> ---
> This perlbug was built using Perl 5.10.0 - Tue Apr  3 07:43:33 UTC 2018
> It is being executed now by  Perl 5.10.0 - Tue Apr  3 07:39:46 UTC 2018.
>
> Site configuration information for perl 5.10.0:
>
> Configured by abuild at Tue Apr  3 07:39:46 UTC 2018.
>
> Summary of my perl5 (revision 5 version 10 subversion 0) configuration:
>   Platform:
>     osname=linux, osvers=2.6.32, archname=x86_64-linux-thread-multi
>     uname='linux sheep58 2.6.32 #1 smp fri jun 14 08:21:43 utc 2013
> (ccab990) x86_64 x86_64 x86_64 gnulinux '
>     config_args='-ds -e -Dprefix=/usr -Dvendorprefix=/usr
> -Dinstallusrbinperl -Dusethreads -Di_db -Di_dbm -Di_ndbm -Di_gdbm
> -Duseshrplib=true -Doptimize=-fmessage-length=0 -O2 -Wall
> -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables
> -fasynchronous-unwind-tables -g -Wall -pipe
> -Accflags=-DPERL_USE_SAFE_PUTENV'
>     hint=recommended, useposix=true, d_sigaction=define
>     useithreads=define, usemultiplicity=define
>     useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
>     use64bitint=define, use64bitall=define, uselongdouble=undef
>     usemymalloc=n, bincompat5005=undef
>   Compiler:
>     cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DPERL_USE_SAFE_PUTENV
> -DDEBUGGING -fno-strict-aliasing -pipe -D_LARGEFILE_SOURCE
> -D_FILE_OFFSET_BITS=64',
>     optimize='-fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2
> -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -Wall
> -pipe',
>     cppflags='-D_REENTRANT -D_GNU_SOURCE -DPERL_USE_SAFE_PUTENV
> -DDEBUGGING -fno-strict-aliasing -pipe'
>     ccversion='', gccversion='4.3.4 [gcc-4_3-branch revision 152973]',
> gccosandvers=''
>     intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
>     d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
>     ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t',
> lseeksize=8
>     alignbytes=8, prototype=define
>   Linker and Libraries:
>     ld='cc', ldflags =' -L/usr/local/lib64'
>     libpth=/lib64 /usr/lib64 /usr/local/lib64
>     libs=-lm -ldl -lcrypt -lpthread
>     perllibs=-lm -ldl -lcrypt -lpthread
>     libc=/lib64/libc-2.11.3.so, so=so, useshrplib=true, libperl=libperl.so
>     gnulibc_version='2.11.3'
>   Dynamic Linking:
>     dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E
> -Wl,-rpath,/usr/lib/perl5/5.10.0/x86_64-linux-thread-multi/CORE'
>     cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib64'
>
> Locally applied patches:
>
>
> ---
> @INC for perl 5.10.0:
>     /usr/lib/perl5/5.10.0/x86_64-linux-thread-multi
>     /usr/lib/perl5/5.10.0
>     /usr/lib/perl5/site_perl/5.10.0/x86_64-linux-thread-multi
>     /usr/lib/perl5/site_perl/5.10.0
>     /usr/lib/perl5/vendor_perl/5.10.0/x86_64-linux-thread-multi
>     /usr/lib/perl5/vendor_perl/5.10.0
>     /usr/lib/perl5/vendor_perl
>
> ---
> Environment for perl 5.10.0:
>     HOME=/home/windl
>     LANG=en_US.UTF-8
>     LANGUAGE (unset)
>     LD_LIBRARY_PATH (unset)
>     LOGDIR (unset)
>
> PATH=/home/windl/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/games:/usr/lib/mit/bin:/usr/lib/mit/sbin
>     PERL_BADLANG (unset)
>     SHELL=/bin/bash
>
>

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About