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

[perl #119863] bug in Math::BigInt with undef

Thread Previous | Thread Next
From:
hb-perlbug @ bsws . de
Date:
September 19, 2013 04:51
Subject:
[perl #119863] bug in Math::BigInt with undef
Message ID:
rt-3.6.HEAD-1873-1379427791-1697.119863-75-0@perl.org
# New Ticket Created by  hb-perlbug@bsws.de 
# Please include the string:  [perl #119863]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org:443/rt3/Ticket/Display.html?id=119863 >



This is a bug report for perl from hb-perlbug@bsws.de,
generated with the help of perlbug 1.39 running under perl 5.16.3.


-----------------------------------------------------------------
Math::BigInt got broken when one component is undef. Unfortunately
the I can only reproduce teh bug in a big custome webapp, but it
comes down to BigInt.pm's objectify() being called with an undef
param, which it won't objectify, due to the check on line 2673ff

        # Don't do anything with undefs.

        unless (defined($a[$i])) {
            next;
        }

callers, i. e. badd(), don't deal with any component being undef.

sub badd 
  {
  # add second arg (BINT or string) to first (BINT) (modifies first)
  # return result as BINT

  # set up parameters
  my ($self,$x,$y,@r) = (ref($_[0]),@_);
  # objectify is costly, so avoid it 
  if ((!ref($_[0])) || (ref($_[0]) ne ref($_[1])))
    {
    ($self,$x,$y,@r) = objectify(2,@_);
    }

  return $x if $x->modify('badd');
  return $upgrade->badd($upgrade->new($x),$upgrade->new($y),@r) if defined $upgrade &&
    ((!$x->isa($self)) || (!$y->isa($self)));

in my case $y ends up being undef, objectify doesn't do anything to it,
and the $y->isa call chokes.
[error] Can't call method "isa" on an undefined value at /usr/libdata/perl5/Math/BigInt.pm line 1131.\n

crude (and almost certainly not correct) fix:

--- BigInt.pm.orig	Tue Sep 17 10:37:09 2013
+++ BigInt.pm	Tue Sep 17 10:32:12 2013
@@ -2670,11 +2670,12 @@ sub objectify {
             next;
         }
 
-        # Don't do anything with undefs.
-
-        unless (defined($a[$i])) {
-            next;
-        }
+#        # Don't do anything with undefs.
+#
+#        unless (defined($a[$i])) {
+#            next;
+#        }
+        $a[$i] //= 0;
 
         # Perl scalars are fed to the appropriate constructor.
 


[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
    category=library
    severity=high
    module=Math::BigInt
---
Site configuration information for perl 5.16.3:

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

Summary of my perl5 (revision 5 version 16 subversion 3) configuration:
   
  Platform:
    osname=openbsd, osvers=5.4, 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
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-DNO_LOCALE_NUMERIC -DNO_LOCALE_COLLATE -fno-strict-aliasing -fno-delete-null-pointer-checks -pipe -fstack-protector -I/usr/local/include',
    optimize='-O2',
    cppflags='-DNO_LOCALE_NUMERIC -DNO_LOCALE_COLLATE -fno-strict-aliasing -fno-delete-null-pointer-checks -pipe -fstack-protector -I/usr/local/include'
    ccversion='', gccversion='4.2.1 20070719 ', gccosandvers='openbsd5.4'
    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 ='-Wl,-E  -fstack-protector'
    libpth=/usr/lib
    libs=-lm -lutil -lc
    perllibs=-lm -lutil -lc
    libc=/usr/lib/libc.a, so=so, useshrplib=true, libperl=libperl.so.14.0
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-R/usr/libdata/perl5/amd64-openbsd/5.16.3/CORE'
    cccdlflags='-DPIC -fPIC ', lddlflags='-shared -fPIC  -fstack-protector'

Locally applied patches:
    

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

---
Environment for perl 5.16.3:
    HOME=/home/brahe
    LANG (unset)
    LANGUAGE (unset)
    LC_CTYPE=en_US.UTF-8
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/brahe/bin:/sbin:/usr/sbin:/bin:/usr/bin:/sbin:/usr/sbin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin:/usr/local/sbin
    PERL_BADLANG (unset)
    SHELL=/bin/ksh


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