develooper Front page | perl.perl5.porters | Postings from September 2019

[perl #134446] Only cache io_socket_proto if protocol is truthy

Thread Previous
From:
perlbug-followup
Date:
September 23, 2019 01:03
Subject:
[perl #134446] Only cache io_socket_proto if protocol is truthy
Message ID:
rt-4.0.24-3775-1569200592-475.134446-75-0@perl.org
# New Ticket Created by   
# Please include the string:  [perl #134446]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=134446 >



This is a bug report for perl from andrew@afresh1.com,
generated with the help of perlbug 1.41 running under perl 5.30.0.


-----------------------------------------------------------------
[Please describe your issue here]

When OpenBSD implemented support for SO_PROTOCOL to getsockopt(2)[1],
suddenly IO/t/cachepropagate-unix.t started failing the 'protocol match'
tests for `new_from_fd` sockets.

I had trouble deciding on whether to actually just remove the entire
cache of protocol from "sub socket" or just to avoid caching it when it
is falsy.  This may cause $sock->protocol to be undef on some systems
that don't support SO_PROTOCOL where it was 0 before, but that is
arguably more correct.

In either case, this causes this test to pass because
$listener->protocol and $new->protocol now match.

$ perl dist/IO/t/cachepropagate-unix.t                            
1..15
ok 1 - stream socket created
ok 2 - protocol defined
ok 3 - domain defined
ok 4 - type defined
ok 5 - spawned a child
ok 6 - domain match
ok 7 - protocol match
ok 8 - type match
ok 9 - datagram socket created
ok 10 - protocol defined
ok 11 - domain defined
ok 12 - type defined
ok 13 - domain match
not ok 14 - protocol match
#   Failed test 'protocol match'
#   at dist/IO/t/cachepropagate-unix.t line 106.
#          got: '1'
#     expected: '0'
ok 15 - type match
# Looks like you failed 1 test of 15.


This test program on OpenBSD-current prints without the attached patch:

    guess: 0
    proto: 1


--- BEGIN testprogram.pl ---

#!/usr/bin/perl;
use strict;
use warnings;

use IO::Socket::UNIX;

use File::Temp   qw< tempdir >;

my $socketpath = tempdir( CLEANUP => 1 ) . '/testsock';

my $old = IO::Socket::UNIX->new(Type => SOCK_DGRAM, Local => $socketpath);
print "guess: " . ( defined $old->protocol ? $old->protocol : 'undef' ) . "\n";
my $protocol = unpack "i", getsockopt($old, Socket::SOL_SOCKET, Socket::SO_PROTOCOL );
print "proto: " . ( defined $protocol ? $protocol : 'undef' ) . "\n";

unlink($socketpath);

--- END testprogram.pl ---

[1] https://github.com/openbsd/src/commit/15b62b7eb58273c052caf9c854e2aa813dbaa7d3


[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
    category=library
    severity=medium
    module=IO::Socket
---
Site configuration information for perl 5.30.0:

Configured by root at Thu Jan  1  0:00:00 UTC 1970.

Summary of my perl5 (revision 5 version 30 subversion 0) configuration:
   
  Platform:
    osname=openbsd
    osvers=6.6
    archname=amd64-openbsd
    uname='openbsd'
    config_args='-dsE -Dopenbsd_distribution=defined -Dccflags=-DNO_LOCALE_NUMERIC -DNO_LOCALE_COLLATE -Dmksymlinks'
    hint=recommended
    useposix=true
    d_sigaction=define
    useithreads=undef
    usemultiplicity=undef
    use64bitint=define
    use64bitall=define
    uselongdouble=undef
    usemymalloc=n
    default_inc_excludes_dot=define
    bincompat5005=undef
  Compiler:
    cc='cc'
    ccflags ='-DNO_LOCALE_NUMERIC -DNO_LOCALE_COLLATE -fno-strict-aliasing -fno-delete-null-pointer-checks -pipe -fstack-protector-strong -D_FORTIFY_SOURCE=2 -I/usr/local/include'
    optimize='-O2'
    cppflags='-DNO_LOCALE_NUMERIC -DNO_LOCALE_COLLATE -fno-strict-aliasing -fno-delete-null-pointer-checks -pipe -fstack-protector-strong -I/usr/local/include'
    ccversion=''
    gccversion='4.2.1 Compatible OpenBSD Clang 8.0.0 (tags/RELEASE_800/final)'
    gccosandvers=''
    intsize=4
    longsize=8
    ptrsize=8
    doublesize=8
    byteorder=12345678
    doublekind=3
    d_longlong=define
    longlongsize=8
    d_longdbl=define
    longdblsize=16
    longdblkind=3
    ivtype='long'
    ivsize=8
    nvtype='double'
    nvsize=8
    Off_t='off_t'
    lseeksize=8
    alignbytes=8
    prototype=define
  Linker and Libraries:
    ld='cc'
    ldflags ='-Wl,-E  -fstack-protector-strong -L/usr/local/lib'
    libpth=/usr/lib /usr/lib
    libs=-lm -lc
    perllibs=-lm -lc
    libc=/usr/lib/libc.so.95.1
    so=so
    useshrplib=true
    libperl=libperl.so.20.0
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dlopen.xs
    dlext=so
    d_dlsymun=undef
    ccdlflags='-Wl,-R/usr/libdata/perl5/amd64-openbsd/CORE'
    cccdlflags='-DPIC -fPIC '
    lddlflags='-shared -fPIC  -fstack-protector-strong -L/usr/local/lib'


---
@INC for perl 5.30.0:
    /usr/local/libdata/perl5/site_perl/amd64-openbsd
    /usr/local/libdata/perl5/site_perl
    /usr/libdata/perl5/amd64-openbsd
    /usr/libdata/perl5

---
Environment for perl 5.30.0:
    HOME=/home/afresh1
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/afresh1/bin:/home/afresh1/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin:/usr/games:.:/usr/ports/infrastructure/bin
    PERL_BADLANG (unset)
    SHELL=/bin/ksh

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