Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Uninitialised memory use when Dumping undef'd stringΒ #24008

@thesamesam

Description

@thesamesam

Description

Uninitialised memory use when dumping an undef'd string.

Reported by damien on #p5p.

Steps to Reproduce

use Devel::Peek;

open my $fh, '>', \my $str;
print $fh "xxxxx";
undef $str;
print $fh "y";
Dump($str);
$ valgrind --track-origins=yes -q perl a.pl
SV = PV(0x508cea0) at 0x50c77a8
  REFCNT = 2
  FLAGS = (POK,pPOK)
  PV = 0x518e880 ==2119893== Conditional jump or move depends on uninitialised value(s)
==2119893==    at 0x4927944: Perl_pv_escape (dump.c:243)
==2119893==    by 0x4928C9E: Perl_pv_pretty (dump.c:400)
==2119893==    by 0x4928C9E: _pv_display_flags.lto_priv.0 (dump.c:424)
==2119893==    by 0x4934903: Perl_do_sv_dump (dump.c:2216)
==2119893==    by 0x487B722: S_do_dump (Peek.xs:334)
==2119893==    by 0x487B7FD: S_pp_dump (Peek.xs:347)
==2119893==    by 0x4A8DFD2: Perl_runops_standard (run.c:41)
==2119893==    by 0x48F8E9B: S_run_body (perl.c:2884)
==2119893==    by 0x48F8E9B: perl_run (perl.c:2799)
==2119893==    by 0x40005B2: main (perlmain.c:127)
==2119893==  Uninitialised value was created by a heap allocation
==2119893==    at 0x484AB04: malloc (vg_replace_malloc.c:447)
==2119893==    by 0x4A96147: Perl_safesysmalloc (util.c:176)
==2119893==    by 0x4A96147: Perl_sv_grow (sv.c:1428)
==2119893==    by 0x49906C3: PerlIOScalar_write (perlio.c:1295)
==2119893==    by 0x4922F8E: Perl_PerlIO_write (perlio.c:2010)
==2119893==    by 0x4922F8E: Perl_do_print (doio.c:2254)
==2119893==    by 0x49D8DA8: Perl_pp_print (pp_hot.c:2148)
==2119893==    by 0x4A8DFD2: Perl_runops_standard (run.c:41)
==2119893==    by 0x48F8E9B: S_run_body (perl.c:2884)
==2119893==    by 0x48F8E9B: perl_run (perl.c:2799)
==2119893==    by 0x40005B2: main (perlmain.c:127)
[...]

Expected behavior

No uninitialised memory use and clean Valgrind results.

Perl configuration

$ perl -V
Summary of my perl5 (revision 5 version 42 subversion 0) configuration:
   
  Platform:
    osname=linux
    osvers=6.17.12
    archname=x86_64-linux
    uname='linux localhost 6.17.12 #1 smp preempt_dynamic fri dec 12 23:20:10 gmt 2025 x86_64 amd ryzen 9 3950x 16-core processor authenticamd gnulinux '
    config_args='-des -Dinstallprefix=/usr -Dinstallusrbinperl=n -Ui_xlocale -Ui_ndbm -Di_gdbm -Ui_db -DDEBUGGING=-g -Dlibpth=/usr/local/lib64 /lib64 /usr/lib64 -Dnoextensions=ODBM_File -Duseshrplib -Darchname=x86_64-linux -Dar=x86_64-pc-linux-gnu-ar -Dcc=x86_64-pc-linux-gnu-gcc -Dcpp=x86_64-pc-linux-gnu-gcc -E -Dld=x86_64-pc-linux-gnu-gcc -Dnm=x86_64-pc-linux-gnu-nm -Dranlib=x86_64-pc-linux-gnu-ranlib -Accflags=-O3 -march=native -flto=jobserver -fno-semantic-interposition -mtls-dialect=gnu2 -g1 -pipe -fcf-protection=none -fdiagnostics-color=always -fdiagnostics-urls=never -frecord-gcc-switches -fdiagnostics-show-context=3 -Wa,-O2 -Wa,-mtune=znver2 -Warray-bounds --param=ggc-min-expand=120 -Wstrict-aliasing -Wfree-nonheap-object -Wuninitialized -Wmaybe-uninitialized -Wreturn-type -Wbuiltin-declaration-mismatch -Wtautological-compare -Werror=lto-type-mismatch -Werror=strict-aliasing -Werror=odr -Warray-bounds -Wstringop-overread -Wstringop-overflow -Wstringop-truncation -Wformat-overflow -Wformat-truncation -Wrestrict -ggdb3 -Wformat -Werror=format-security -fno-strict-aliasing -DNO_PERL_RAND_SEED -Doptimize=-O3 -march=native -flto=jobserver -fno-semantic-interposition -mtls-dialect=gnu2 -g1 -pipe -fcf-protection=none -fdiagnostics-color=always -fdiagnostics-urls=never -frecord-gcc-switches -fdiagnostics-show-context=3 -Wa,-O2 -Wa,-mtune=znver2 -Warray-bounds --param=ggc-min-expand=120 -Wstrict-aliasing -Wfree-nonheap-object -Wuninitialized -Wmaybe-uninitialized -Wreturn-type -Wbuiltin-declaration-mismatch -Wtautological-compare -Werror=lto-type-mismatch -Werror=strict-aliasing -Werror=odr -Warray-bounds -Wstringop-overread -Wstringop-overflow -Wstringop-truncation -Wformat-overflow -Wformat-truncation -Wrestrict -ggdb3 -Wformat -Werror=format-security -fno-strict-aliasing -Dldflags=-O3 -march=native -flto=jobserver -fno-semantic-interposition -mtls-dialect=gnu2 -g1 -pipe -fcf-protection=none -fdiagnostics-color=always -fdiagnostics-urls=never -frecord-gcc-switches -fdiagnostics-show-context=3 -Wa,-O2 -Wa,-mtune=znver2 -Warray-bounds --param=ggc-min-expand=120 -Werror=lto-type-mismatch -Werror=strict-aliasing -Werror=odr -Warray-bounds -Wstringop-overread -Wstringop-overflow -Wstringop-truncation -Wformat-overflow -Wformat-truncation -Wrestrict -Wl,-O1 -Wl,--as-needed -Wl,-z,pack-relative-relocs -flto=jobserver -Wl,--defsym=__gentoo_check_ldflags__=0 -ggdb3 -Dprefix=/usr -Dsiteprefix=/usr/local -Dvendorprefix=/usr -Dscriptdir=/usr/bin -Dprivlib=/usr/lib64/perl5/5.42 -Darchlib=/usr/lib64/perl5/5.42/x86_64-linux -Dsitelib=/usr/local/lib64/perl5/5.42 -Dsitearch=/usr/local/lib64/perl5/5.42/x86_64-linux -Dvendorlib=/usr/lib64/perl5/vendor_perl/5.42 -Dvendorarch=/usr/lib64/perl5/vendor_perl/5.42/x86_64-linux -Dman1dir=/usr/share/man/man1 -Dman3dir=/usr/share/man/man3 -Dsiteman1dir=/usr/local/man/man1 -Dsiteman3dir=/usr/local/man/man3 -Dvendorman1dir=/usr/share/man/man1 -Dvendorman3dir=/usr/share/man/man3 -Dman1ext=1 -Dman3ext=3pm -Dlibperl=libperl.so.5.42.0 -Dlocincpth=/usr/include  -Dglibpth=/lib64 /usr/lib64  -Duselargefiles -Duse64bitint -Dd_semctl_semun -Dcf_by=Gentoo -Dmyhostname=localhost -Dperladmin=root@localhost -Ud_csh -Dsh=/bin/sh -Dtargetsh=/bin/sh -Uusenm'
    hint=recommended
    useposix=true
    d_sigaction=define
    useithreads=undef
    usemultiplicity=undef
    use64bitint=define
    use64bitall=define
    uselongdouble=undef
    usemymalloc=n
    default_inc_excludes_dot=define
  Compiler:
    cc='x86_64-pc-linux-gnu-gcc'
    ccflags ='-O3 -march=native -flto=jobserver -fno-semantic-interposition -mtls-dialect=gnu2 -g1 -pipe -fcf-protection=none -fdiagnostics-color=always -fdiagnostics-urls=never -frecord-gcc-switches -fdiagnostics-show-context=3 -Wa,-O2 -Wa,-mtune=znver2 -Warray-bounds --param=ggc-min-expand=120 -Wstrict-aliasing -Wfree-nonheap-object -Wuninitialized -Wmaybe-uninitialized -Wreturn-type -Wbuiltin-declaration-mismatch -Wtautological-compare -Werror=lto-type-mismatch -Werror=strict-aliasing -Werror=odr -Warray-bounds -Wstringop-overread -Wstringop-overflow -Wstringop-truncation -Wformat-overflow -Wformat-truncation -Wrestrict -ggdb3 -Wformat -Werror=format-security -fno-strict-aliasing -DNO_PERL_RAND_SEED -fwrapv -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'
    optimize='-O3 -march=native -flto=jobserver -fno-semantic-interposition -mtls-dialect=gnu2 -g1 -pipe -fcf-protection=none -fdiagnostics-color=always -fdiagnostics-urls=never -frecord-gcc-switches -fdiagnostics-show-context=3 -Wa,-O2 -Wa,-mtune=znver2 -Warray-bounds --param=ggc-min-expand=120 -Wstrict-aliasing -Wfree-nonheap-object -Wuninitialized -Wmaybe-uninitialized -Wreturn-type -Wbuiltin-declaration-mismatch -Wtautological-compare -Werror=lto-type-mismatch -Werror=strict-aliasing -Werror=odr -Warray-bounds -Wstringop-overread -Wstringop-overflow -Wstringop-truncation -Wformat-overflow -Wformat-truncation -Wrestrict -ggdb3 -Wformat -Werror=format-security -fno-strict-aliasing'
    cppflags='-O3 -march=native -flto=jobserver -fno-semantic-interposition -mtls-dialect=gnu2 -g1 -pipe -fcf-protection=none -fdiagnostics-color=always -fdiagnostics-urls=never -frecord-gcc-switches -fdiagnostics-show-context=3 -Wa,-O2 -Wa,-mtune=znver2 -Warray-bounds --param=ggc-min-expand=120 -Wstrict-aliasing -Wfree-nonheap-object -Wuninitialized -Wmaybe-uninitialized -Wreturn-type -Wbuiltin-declaration-mismatch -Wtautological-compare -Werror=lto-type-mismatch -Werror=strict-aliasing -Werror=odr -Warray-bounds -Wstringop-overread -Wstringop-overflow -Wstringop-truncation -Wformat-overflow -Wformat-truncation -Wrestrict -ggdb3 -Wformat -Werror=format-security -fno-strict-aliasing -DNO_PERL_RAND_SEED -fwrapv'
    ccversion=''
    gccversion='16.0.0 20251213 (experimental) e9c12ffd710484751428fc301a272e16f641cd56'
    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='x86_64-pc-linux-gnu-gcc'
    ldflags ='-O3 -march=native -flto=jobserver -fno-semantic-interposition -mtls-dialect=gnu2 -g1 -pipe -fcf-protection=none -fdiagnostics-color=always -fdiagnostics-urls=never -frecord-gcc-switches -fdiagnostics-show-context=3 -Wa,-O2 -Wa,-mtune=znver2 -Warray-bounds --param=ggc-min-expand=120 -Werror=lto-type-mismatch -Werror=strict-aliasing -Werror=odr -Warray-bounds -Wstringop-overread -Wstringop-overflow -Wstringop-truncation -Wformat-overflow -Wformat-truncation -Wrestrict -Wl,-O1 -Wl,--as-needed -Wl,-z,pack-relative-relocs -flto=jobserver -Wl,--defsym=__gentoo_check_ldflags__=0 -ggdb3'
    libpth=/usr/local/lib64 /lib64 /usr/lib64 /usr/local/lib /usr/lib
    libs=-lgdbm -ldl -lm -lcrypt -lutil -lc -lgdbm_compat
    perllibs=-ldl -lm -lcrypt -lutil -lc
    libc=/lib/../lib64/libc.so.6
    so=so
    useshrplib=true
    libperl=libperl.so.5.42.0
    gnulibc_version='2.42'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs
    dlext=so
    d_dlsymun=undef
    ccdlflags='-Wl,-E'
    cccdlflags='-fPIC'
    lddlflags='-shared -O3 -march=native -flto=jobserver -fno-semantic-interposition -mtls-dialect=gnu2 -g1 -pipe -fcf-protection=none -fdiagnostics-color=always -fdiagnostics-urls=never -frecord-gcc-switches -fdiagnostics-show-context=3 -Wa,-O2 -Wa,-mtune=znver2 -Warray-bounds --param=ggc-min-expand=120 -Wstrict-aliasing -Wfree-nonheap-object -Wuninitialized -Wmaybe-uninitialized -Wreturn-type -Wbuiltin-declaration-mismatch -Wtautological-compare -Werror=lto-type-mismatch -Werror=strict-aliasing -Werror=odr -Warray-bounds -Wstringop-overread -Wstringop-overflow -Wstringop-truncation -Wformat-overflow -Wformat-truncation -Wrestrict -ggdb3 -Wformat -Werror=format-security -fno-strict-aliasing -O3 -march=native -flto=jobserver -fno-semantic-interposition -mtls-dialect=gnu2 -g1 -pipe -fcf-protection=none -fdiagnostics-color=always -fdiagnostics-urls=never -frecord-gcc-switches -fdiagnostics-show-context=3 -Wa,-O2 -Wa,-mtune=znver2 -Warray-bounds --param=ggc-min-expand=120 -Werror=lto-type-mismatch -Werror=strict-aliasing -Werror=odr -Warray-bounds -Wstringop-overread -Wstringop-overflow -Wstringop-truncation -Wformat-overflow -Wformat-truncation -Wrestrict -Wl,-O1 -Wl,--as-needed -Wl,-z,pack-relative-relocs -flto=jobserver -Wl,--defsym=__gentoo_check_ldflags__=0 -ggdb3'


Characteristics of this binary (from libperl): 
  Compile-time options:
    HAS_LONG_DOUBLE
    HAS_STRTOLD
    HAS_TIMES
    NO_PERL_RAND_SEED
    PERLIO_LAYERS
    PERL_COPY_ON_WRITE
    PERL_DONT_CREATE_GVSV
    PERL_HASH_FUNC_SIPHASH13
    PERL_HASH_USE_SBOX32
    PERL_MALLOC_WRAP
    PERL_OP_PARENT
    PERL_PRESERVE_IVUV
    PERL_USE_SAFE_PUTENV
    USE_64_BIT_ALL
    USE_64_BIT_INT
    USE_LARGE_FILES
    USE_LOCALE
    USE_LOCALE_COLLATE
    USE_LOCALE_CTYPE
    USE_LOCALE_NUMERIC
    USE_LOCALE_TIME
    USE_PERLIO
    USE_PERL_ATOF
  Locally applied patches:
    0001-Fix-hpux-hints.patch
    - Fix hpux hints
    0002-aix-gcc-detection-and-shared-library-soname-support.patch
    - aix gcc detection and shared library soname support
    0003-cpan-ExtUtils-MakeMaker-drop-PORTAGE_TMPDIR-from-LD_.patch
    - cpan/ExtUtils-MakeMaker: drop $PORTAGE_TMPDIR from LD_RUN_PATH
    - Bug: https://bugs.gentoo.org/105054
    0004-Remove-rpath-and-append-LDFLAGS-to-lddlflags.patch
    - Remove -rpath and append LDFLAGS to lddlflags
    0005-Add-headers-for-opensolaris.patch
    - Add headers for opensolaris
    0006-List-packaged-patches-in-patchlevel.h.patch
    - List packaged patches for perl-5.42.0-r1(perl-5.42.0-patches-1) in patchlevel.h
    - Bug: https://bugs.debian.org/567489
    0007-Cleanup-PATH-and-shrpenv.patch
    - Cleanup PATH and shrpenv
    0008-Tweak-enc2xs-to-follow-symlinks-and-ignore-missing-I.patch
    - Tweak enc2xs to follow symlinks and ignore missing @INC directories.
    - Bug: https://bugs.debian.org/290336
    0009-darwin-Use-CC-to-link.patch
    - darwin: Use $CC to link
    - Bug: https://bugs.gentoo.org/297751
    0010-Provide-a-sensible-INSTALLDIRS-default-for-modules-i.patch
    - Provide a sensible INSTALLDIRS default for modules installed from CPAN.
    0011-Fix-interix-hints.patch
    - Fix interix hints
    0012-Set-libperl-soname.patch
    - Set libperl soname
    - Bug: https://bugs.gentoo.org/286840
    0013-Add-etc-perl-to-INC.patch
    - Add /etc/perl to @INC
    0014-cpan-ExtUtils-MakeMaker-remove-targets-that-generate.patch
    - cpan/ExtUtils-MakeMaker: remove targets that generate perllocal.pod
    0015-Don-t-force-fstack-protector-on-everyone.patch
    - Don't force -fstack-protector on everyone
    - Bug: https://bugs.gentoo.org/348557
    0016-Do-not-set-custom-CFLAGS-in-cpan-Digest-SHA.patch
    - Do not set custom CFLAGS in cpan/Digest-SHA
    - Bug: https://bugs.gentoo.org/506818
    0017-Configure-Don-t-include-sources-in-usr-local-for-com.patch
    - Configure: Don't include sources in /usr/local/ for compiling perl
    0018-cpan-IO-Socket-IP-Disable-network-tests.patch
    - cpan/IO-Socket-IP: Disable network tests
    0019-Fix-EUMM-podlocal-tests.patch
    - Fix EUMM podlocal tests
    0020-Skip-auto-linking-cl-and-pthread.patch
    - Skip auto-linking nsl and cl
    - Bug: https://rt.perl.org/Public/Bug/Display.html?id=13148
    0021-Disable-porting-tests-which-create-fun-false-failure.patch
    - Disable porting tests which create fun false-failures all over travis
    0022-Disable-PathTools-tests-which-fails-under-sandboxing.patch
    - Disable PathTools tests which fails under sandboxing
    - Bug: https://bugs.gentoo.org/645084
    0023-Fix-CPAN-FirstTime-defaults-with-nonexisting-site-di.patch
    - Fix CPAN::FirstTime defaults with nonexisting site dirs if a parent is writable
    - Bug: https://bugs.debian.org/688842
    0024-Pass-LD-settings-through-to-subdirectories.patch
    - Pass LD settings through to subdirectories
    - Bug: https://bugs.debian.org/758471
    0025-Respect-umask-during-installation.patch
    - Respect umask during installation
    0026-Fix-parallel-building.patch
    - Fix parallel building
    0027-Add-support-for-Dgentoolibdirs-note-hashes-in-uconfi.patch
    - Add support for -Dgentoolibdirs
    100-newFOROP-fix-crash-when-optimizing-2-var-for-over-bu.patch
    - Fix for keyword segfaulting when iterating over multiple values at a time
    - Bug: https://bugs.gentoo.org/964379
    - Bug: https://github.com/Perl/perl5/issues/23405
    101-class.c-gracefully-handle-reader-writer-after-strict.patch
    - Gracefully handle reader definition after strict error
    - Bug: https://github.com/Perl/perl5/issues/23511
    102-use-5.41-affects-current-line-source-encoding.patch
    - 5.41 use affects current line source::encoding
    - Bug: https://github.com/Perl/perl5/issues/23881
    103-Turn-off-POSIX-2008-locales-on-AIX.patch
    - Turn off POSIX 2008 locales on AIX
    - Bug: https://github.com/Perl/perl5/issues/23825
  Built under linux
  Compiled at Dec 13 2025 13:55:24
  @INC:
    /etc/perl
    /usr/local/lib64/perl5/5.42/x86_64-linux
    /usr/local/lib64/perl5/5.42
    /usr/lib64/perl5/vendor_perl/5.42/x86_64-linux
    /usr/lib64/perl5/vendor_perl/5.42
    /usr/lib64/perl5/5.42/x86_64-linux
    /usr/lib64/perl5/5.42

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