develooper Front page | perl.perl5.porters | Postings from October 2016

[perl #129825] Overloaded integer constants are prematurelydeallocated

Thread Previous | Thread Next
From:
Daniel Șuteu
Date:
October 7, 2016 12:11
Subject:
[perl #129825] Overloaded integer constants are prematurelydeallocated
Message ID:
rt-4.0.24-23767-1475842302-146.129825-75-0@perl.org
# New Ticket Created by  Daniel Șuteu 
# Please include the string:  [perl #129825]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=129825 >


This is a bug report for perl from trizenx@gmail.com,
generated with the help of perlbug 1.40 running under perl 5.24.0.


-----------------------------------------------------------------

It seems like there is a premature deallocation of integer overloaded
constants which are stored inside an object. When the object is destroyed,
the constants are destroyed as well, which leads to undefined behavior.

Bellow is the code illustrating the issue:

#######################################

package Foo;

#use Math::BigNum qw(:constant);    # correct   (perl=5.18.4) ; segfault
 (perl>=5.24.0)
#use bignum only => 'GMP';          #                         ; error
(perl>=5.18.4)
use Math::GMP qw(:constant);        # correct   (perl=5.18.4) ; incorrect
(perl>=5.24.0)

sub new {
    my $class = shift;
    my $self  = {};
    my %param = @_;
    $self->{name} = $param{name};
    bless $self, $class;
}

sub set {
    my $self = shift;
    my %kv   = @_;

    while (my ($k, $v) = each %kv) {
        $self->{hash}->{$k} = $v;
    }
    1;
}

sub show {
    my $self = shift;
    my $kv   = $self->{hash};

    printf "--- %s ---\n", $self->{name};

    my %kloop = %$kv;
    while (my ($k, $v) = each %kloop) {
       $v = 'UNDEF' if !defined $v;
       print "$k => $v\n";
    }
    1;
}

sub DESTROY {
    my $self = shift;
    show($self);
    1;
}

#my $foo;                             # NOTE: uncommenting this line, fixes
the bug
$foo = Foo->new(name => 'explicit');
$foo->set(1 => 2, 3 => 4, 5 => 6);
$foo->show();
undef $foo;

$foo = Foo->new(name => 'implicit');
$foo->set(1 => 2, 3 => 4, 5 => 6);
$foo->show();

######################### END-OF-CODE #########################


The output under perl=5.24.0 with `Math::GMP qw(:constant)` is:

--- explicit ---
1 => 2
3 => 4
5 => 6
--- explicit ---
5 => 6
1 => 2
3 => 4
--- implicit ---
1 => 2
3 => 4
5 => 6
--- implicit ---
5 => UNDEF
1 => 2
3 => 4

-----------------------------------------------------------------
---
Flags:
    category=core
    severity=medium
---
Site configuration information for perl 5.24.0:

Configured by builduser at Thu Sep  8 13:45:49 CEST 2016.

Summary of my perl5 (revision 5 version 24 subversion 0) configuration:

  Platform:
    osname=linux, osvers=4.7.3-1-arch, archname=x86_64-linux-thread-multi
    uname='linux flo-64 4.7.3-1-arch #1 smp preempt wed sep 7 17:57:38 cest
2016 x86_64 gnulinux '
    config_args='-des -Dusethreads -Duseshrplib -Doptimize=-march=x86-64
-mtune=generic -O2 -pipe -fstack-protector-strong -Dprefix=/usr
-Dvendorprefix=/usr -Dprivlib=/usr/share/perl5/core_perl
-Darchlib=/usr/lib/perl5/core_perl -Dsitelib=/usr/share/perl5/site_perl
-Dsitearch=/usr/lib/perl5/site_perl
-Dvendorlib=/usr/share/perl5/vendor_perl
-Dvendorarch=/usr/lib/perl5/vendor_perl -Dscriptdir=/usr/bin/core_perl
-Dsitescript=/usr/bin/site_perl -Dvendorscript=/usr/bin/vendor_perl
-Dinc_version_list=none -Dman1ext=1perl -Dman3ext=3perl
-Dcccdlflags='-fPIC' -Dlddlflags=-shared
-Wl,-O1,--sort-common,--as-needed,-z,relro
-Dldflags=-Wl,-O1,--sort-common,--as-needed,-z,relro'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=define, usemultiplicity=define
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fwrapv
-fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include
-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-march=x86-64 -mtune=generic -O2 -pipe
-fstack-protector-strong',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -fwrapv -fno-strict-aliasing -pipe
-fstack-protector-strong -I/usr/local/include'
    ccversion='', gccversion='6.1.1 20160802', 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,-O1,--sort-common,--as-needed,-z,relro
-fstack-protector-strong -L/usr/local/lib'
    libpth=/usr/local/lib
/usr/lib/gcc/x86_64-pc-linux-gnu/6.1.1/include-fixed /usr/lib /lib/../lib
/usr/lib/../lib /lib /lib64 /usr/lib64
    libs=-lpthread -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc
-lgdbm_compat
    perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    libc=libc-2.24.so, so=so, useshrplib=true, libperl=libperl.so
    gnulibc_version='2.24'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E
-Wl,-rpath,/usr/lib/perl5/core_perl/CORE'
    cccdlflags='-fPIC', lddlflags='-shared
-Wl,-O1,--sort-common,--as-needed,-z,relro -L/usr/local/lib
-fstack-protector-strong'


---
@INC for perl 5.24.0:
    /usr/lib/perl5/site_perl
    /usr/share/perl5/site_perl
    /usr/lib/perl5/vendor_perl
    /usr/share/perl5/vendor_perl
    /usr/lib/perl5/core_perl
    /usr/share/perl5/core_perl
    .

---
Environment for perl 5.24.0:
    HOME=/home/swampyx
    LANG=en_US.UTF-8
    LANGUAGE (unset)
    LC_CTYPE=en_US.UTF-8
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)

PATH=/usr/lib/ccache/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/usr/share/perl6/vendor/bin
    PERL_BADLANG (unset)
    SHELL=/usr/bin/zsh


Thread Previous | Thread Next


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