Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Use of uninitialized value" in warn() with constant folding and overloaded numbers #16349

Closed
p5pRT opened this issue Jan 5, 2018 · 9 comments
Labels

Comments

@p5pRT
Copy link
Collaborator

@p5pRT p5pRT commented Jan 5, 2018

Migrated from rt.perl.org#132683 (status was 'resolved')

Searchable as RT132683$

@p5pRT

This comment has been minimized.

Copy link
Collaborator Author

@p5pRT p5pRT commented Jan 5, 2018

From trizen@protonmail.com

Hi,

There seems to be a minor issue​: when warn() is used in an overloaded built-in function which is subject to constant folding and the argument is an overloaded number (with overload​::constant), it displays "Use of uninitialized value in warn", although no uninitialized value is passed to warn().

Example​:

use strict;
use warnings;

package Foo;

use overload log => sub {
  warn "here\n"; # Use of uninitialized value in warn
  CORE​::log($_[0]->{value});
};

sub import {
  overload​::constant
  integer => sub { __PACKAGE__->new($_[0]) };
}

sub new {
  my ($class, $value) = @​_;
  bless {value => $value}, $class;
}

package main;

BEGIN { Foo->import }
print log(2), "\n";

The output is​:

Use of uninitialized value in warn at bug.pl line 7.
here
0.693147180559945

This warning happens at compile-time, as can be illustrated with `perl -c`​:

$ perl -c x.pl
Use of uninitialized value in warn at x.pl line 7.

here

x.pl syntax OK

The issue was reproduced with perl-5.18.4, perl-5.26.1 and perl-5.27.7.

Output of `perlbug -d`​:


Flags​:
  category=core
  severity=low


Site configuration information for perl 5.26.1​:

Configured by builduser at Sat Sep 23 16​:41​:42 CEST 2017.

Summary of my perl5 (revision 5 version 26 subversion 1) configuration​:

  Platform​:
  osname=linux
  osvers=4.13.3-1-arch
  archname=x86_64-linux-thread-multi
  uname='linux flo-64 4.13.3-1-arch #1 smp preempt thu sep 21 20​:33​:16 cest 2017 x86_64 gnulinux '
  config_args='-des -Dusethreads -Duseshrplib -Doptimize=-march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt -Dprefix=/usr -Dvendorprefix=/usr -Dprivlib=/usr/share/perl5/core_perl -Darchlib=/usr/lib/perl5/5.26/core_perl -Dsitelib=/usr/share/perl5/site_perl -Dsitearch=/usr/lib/perl5/5.26/site_perl -Dvendorlib=/usr/share/perl5/vendor_perl -Dvendorarch=/usr/lib/perl5/5.26/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,-z,now -Dldflags=-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now'
  hint=recommended
  useposix=true
  d_sigaction=define
  useithreads=define
  usemultiplicity=define
  use64bitint=define
  use64bitall=define
  uselongdouble=undef
  usemymalloc=n
  default_inc_excludes_dot=define
  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 -D_FORTIFY_SOURCE=2'
  optimize='-march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt'
  cppflags='-D_REENTRANT -D_GNU_SOURCE -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include'
  ccversion=''
  gccversion='7.2.0'
  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,-z,now -fstack-protector-strong -L/usr/local/lib'
  libpth=/usr/local/lib /usr/lib/gcc/x86_64-pc-linux-gnu/7.2.0/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.26.so
  so=so
  useshrplib=true
  libperl=libperl.so
  gnulibc_version='2.26'
  Dynamic Linking​:
  dlsrc=dl_dlopen.xs
  dlext=so
  d_dlsymun=undef
  ccdlflags='-Wl,-E -Wl,-rpath,/usr/lib/perl5/5.26/core_perl/CORE'
  cccdlflags='-fPIC'
  lddlflags='-shared -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -L/usr/local/lib -fstack-protector-strong'


@​INC for perl 5.26.1​:
  /usr/lib/perl5/5.26/site_perl
  /usr/share/perl5/site_perl
  /usr/lib/perl5/5.26/vendor_perl
  /usr/share/perl5/vendor_perl
  /usr/lib/perl5/5.26/core_perl
  /usr/share/perl5/core_perl


Environment for perl 5.26.1​:
  HOME=/home/swampyx
  LANG=en_US.UTF-8
  LANGUAGE=
  LC_ADDRESS=
  LC_ALL=
  LC_COLLATE=
  LC_CTYPE=en_US.UTF-8
  LC_IDENTIFICATION=
  LC_MEASUREMENT=
  LC_MESSAGES=
  LC_MONETARY=
  LC_NAME=
  LC_NUMERIC=
  LC_PAPER=
  LC_TELEPHONE=
  LC_TIME=
  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

@p5pRT

This comment has been minimized.

Copy link
Collaborator Author

@p5pRT p5pRT commented Jan 5, 2018

@p5pRT

This comment has been minimized.

Copy link
Collaborator Author

@p5pRT p5pRT commented Feb 21, 2018

From @tonycoz

On Thu, 04 Jan 2018 23​:09​:07 -0800, trizen@​protonmail.com wrote​:

Hi,

There seems to be a minor issue​: when warn() is used in an overloaded
built-in function which is subject to constant folding and the
argument is an overloaded number (with overload​::constant), it
displays "Use of uninitialized value in warn", although no
uninitialized value is passed to warn().

Try the attached.

Thanks,
Tony

@p5pRT

This comment has been minimized.

Copy link
Collaborator Author

@p5pRT p5pRT commented Feb 21, 2018

From @tonycoz

0001-perl-132683-don-t-try-to-convert-PL_sv_placeholder-i.patch
From 536b91a5640beba18185316f709279a8d2e588be Mon Sep 17 00:00:00 2001
From: Tony Cook <tony@develop-help.com>
Date: Wed, 21 Feb 2018 16:24:08 +1100
Subject: (perl #132683) don't try to convert PL_sv_placeholder into a CV

Constant folding sets PL_warnhook to PERL_WARNHOOK_FATAL, which is
&PL_sv_placeholder, an undef SV.

If warn() is called while constant folding, invoke_exception_hook()
attempts to use the value of a non-NULL PL_warnhook as a CV, which
caused an undefined value warning.

invoke_exception_hook() now treats a PL_warnhook of PERL_WARNHOOK_FATAL
the same as NULL, falling back to the normal warning handling which
throws an exception to abort constant folding.
---
 t/lib/warnings/util | 29 +++++++++++++++++++++++++++++
 util.c              |  2 +-
 2 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/t/lib/warnings/util b/t/lib/warnings/util
index e82d6a6617..92be6efa73 100644
--- a/t/lib/warnings/util
+++ b/t/lib/warnings/util
@@ -106,3 +106,32 @@ no warnings 'portable' ;
    $a =  oct "0047777777777" ;
 EXPECT
 Octal number > 037777777777 non-portable at - line 5.
+########
+# util.c
+# NAME 132683: Use of uninitialized value" in warn() with constant folding and overloaded numbers
+use strict;
+use warnings;
+
+package Foo;
+
+use overload log => sub {
+    warn "here\n";                  # Use of uninitialized value in warn
+    CORE::log($_[0]->{value});
+};
+
+sub import {
+    overload::constant
+        integer => sub { __PACKAGE__->new($_[0]) };
+}
+
+sub new {
+    my ($class, $value) = @_;
+    bless {value => $value}, $class;
+}
+
+package main;
+
+BEGIN { Foo->import }
+my $x = log(2);
+EXPECT
+here
diff --git a/util.c b/util.c
index 647f53307d..07ca5c7b1d 100644
--- a/util.c
+++ b/util.c
@@ -1534,7 +1534,7 @@ S_invoke_exception_hook(pTHX_ SV *ex, bool warn)
     /* sv_2cv might call Perl_croak() or Perl_warner() */
     SV * const oldhook = *hook;
 
-    if (!oldhook)
+    if (!oldhook || oldhook == PERL_WARNHOOK_FATAL)
 	return FALSE;
 
     ENTER;
-- 
2.11.0

@p5pRT

This comment has been minimized.

Copy link
Collaborator Author

@p5pRT p5pRT commented Feb 21, 2018

The RT System itself - Status changed from 'new' to 'open'

@p5pRT

This comment has been minimized.

Copy link
Collaborator Author

@p5pRT p5pRT commented Aug 30, 2018

From @tonycoz

On Tue, 20 Feb 2018 21​:24​:56 -0800, tonyc wrote​:

On Thu, 04 Jan 2018 23​:09​:07 -0800, trizen@​protonmail.com wrote​:

Hi,

There seems to be a minor issue​: when warn() is used in an overloaded
built-in function which is subject to constant folding and the
argument is an overloaded number (with overload​::constant), it
displays "Use of uninitialized value in warn", although no
uninitialized value is passed to warn().

Try the attached.

Applied as 2460a49.

Tony

@p5pRT

This comment has been minimized.

Copy link
Collaborator Author

@p5pRT p5pRT commented Aug 30, 2018

@tonycoz - Status changed from 'open' to 'pending release'

@p5pRT

This comment has been minimized.

Copy link
Collaborator Author

@p5pRT p5pRT commented May 22, 2019

From @khwilliamson

Thank you for filing this report. You have helped make Perl better.

With the release today of Perl 5.30.0, this and 160 other issues have been
resolved.

Perl 5.30.0 may be downloaded via​:
https://metacpan.org/release/XSAWYERX/perl-5.30.0

If you find that the problem persists, feel free to reopen this ticket.

@p5pRT

This comment has been minimized.

Copy link
Collaborator Author

@p5pRT p5pRT commented May 22, 2019

@khwilliamson - Status changed from 'pending release' to 'resolved'

@p5pRT p5pRT closed this May 22, 2019
@p5pRT p5pRT added the Severity Low label Oct 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.