Skip to content

Segfault on warnings when using the value of a hash with undefined value specified as the key #19147

@choroba

Description

@choroba

Module:

Description

Perl crashes with a segfault when a variable with undefined value is used as a hash key and the hash doesn't have a value associated to the empty string, and the resulting undefined value is used in an expression under warnings. An example probably explains it better:

Steps to Reproduce

The following line is enough:

perl -we '-$a{$b}'

It outputs:

Useless use of negation (-) in void context at -e line 1.
Name "main::a" used only once: possible typo at -e line 1.
Use of uninitialized value $b in hash element at -e line 1.
Segmentation fault (core dumped)

Interestingly, without warnings the segfault doesn't happen.

Expected behavior

The segfault shouldn't happen.

Perl configuration

# perl -V output goes here
Summary of my perl5 (revision 5 version 33 subversion 9) configuration:
  Commit id: 6c6de3559b93537c4caaa96be7e461b4cfdfbd94
  Platform:
    osname=linux
    osvers=5.3.18-lp152.72-default
    archname=x86_64-linux-thread-multi
    uname='linux triangle 5.3.18-lp152.72-default #1 smp wed apr 14 10:13:15 utc 2021 (013936d) x86_64 x86_64 x86_64 gnulinux '
    config_args='-Dusethreads -Dprefix=/home/choroba/localperl -Dusedevel -des'
    hint=recommended
    useposix=true
    d_sigaction=define
    useithreads=define
    usemultiplicity=define
    use64bitint=define
    use64bitall=define
    uselongdouble=undef
    usemymalloc=n
    default_inc_excludes_dot=define
  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='-O2'
    cppflags='-D_REENTRANT -D_GNU_SOURCE -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include'
    ccversion=''
    gccversion='7.5.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 =' -fstack-protector-strong -L/usr/local/lib'
    libpth=/usr/local/lib /usr/x86_64-suse-linux/lib /usr/lib /lib64 /usr/lib64 /lib /usr/local/lib64
    libs=-lpthread -ldl -lm -lcrypt -lutil -lc
    perllibs=-lpthread -ldl -lm -lcrypt -lutil -lc
    libc=libc-2.26.so
    so=so
    useshrplib=false
    libperl=libperl.a
    gnulibc_version='2.26'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs
    dlext=so
    d_dlsymun=undef
    ccdlflags='-Wl,-E'
    cccdlflags='-fPIC'
    lddlflags='-shared -O2 -L/usr/local/lib -fstack-protector-strong'


Characteristics of this binary (from libperl): 
  Compile-time options:
    HAS_TIMES
    MULTIPLICITY
    PERLIO_LAYERS
    PERL_COPY_ON_WRITE
    PERL_DONT_CREATE_GVSV
    PERL_IMPLICIT_CONTEXT
    PERL_MALLOC_WRAP
    PERL_OP_PARENT
    PERL_PRESERVE_IVUV
    PERL_USE_DEVEL
    USE_64_BIT_ALL
    USE_64_BIT_INT
    USE_ITHREADS
    USE_LARGE_FILES
    USE_LOCALE
    USE_LOCALE_COLLATE
    USE_LOCALE_CTYPE
    USE_LOCALE_NUMERIC
    USE_LOCALE_TIME
    USE_PERLIO
    USE_PERL_ATOF
    USE_REENTRANT_API
    USE_THREAD_SAFE_LOCALE
  Built under linux
  Compiled at Apr 28 2021 18:53:52
  @INC:
    /home/choroba/localperl/lib/site_perl/5.33.9/x86_64-linux-thread-multi
    /home/choroba/localperl/lib/site_perl/5.33.9
    /home/choroba/localperl/lib/5.33.9/x86_64-linux-thread-multi
    /home/choroba/localperl/lib/5.33.9

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions