-
Notifications
You must be signed in to change notification settings - Fork 589
Description
Description
If eval string is used when the debugger is enabled then we may or may not leak debugging meta data in the stash depending on how the eval fails.
When $^P
is set to an integer with the 0x400
bit set (and maybe other bits) the debugger mode is enabled and when code is compiled a copy of the lines that were compiled is stashed away in %::
in a slot named "_<(eval $eval_ctr)"
, we make attempts to arrange that this slot is deleted if the eval fails. However there are a variety of ways that the compilation phase of eval may fail. If the failure triggers a Perl_croak()
then we leak the debugging data and do not delete the entry.
Two easy ways to see this are to eval "BEGIN{die}"
, and another is trigger 10 or more syntax errors in the eval text, which will cause the parser to trigger a croak. Any error pathway that triggers a croak may cause this outcome and there are a handful of special cases where the parser /will/ croak.
Thus "1+"
will fail compile in a way that cleans up "_<(eval $eval_ctr)"
, but "1+;1+;1+;1+;1+;1+;1+;1+;1+;1+;"
will trigger a croak and the "_<(eval $eval_ctr)"
will be left behind.
t/comp/retainedlines.t
attempts to test this behavior, but it only uses very simple code to eval, and it doesnt trigger a croak, which exposes the issue. I noticed this because I am trying to make the parser stop after the first syntax error it encounters, and this is easiest done by croaking, but that exposes the underlying bug in this ticket which exists with or without the new logic.
Steps to Reproduce
This should output "0 0", it outputs "0 1" instead.
perl -le'for (1,10) { $^P=0x400; eval "1+;" x $_; my $count=0; /eval/ and $count++ for keys %::; push @ret,$count } print "@ret"'
0 1
Expected behavior
We should clean up the entries consistently. The output from the above script should be "0 0"
.
Or I guess alternatively we shouldn't care about these "stash droppings". Although that seems like a great way to make the debugger leak memory. On the other hand, its not clear to me if we clean up these droppings if the eval is successful, so I am not sure if we should care. It feels like we should, but maybe not.
Perl configuration
$ ./perl -Ilib -V
Summary of my perl5 (revision 5 version 37 subversion 4) configuration:
Derived from: ebc2efe6583f7cf7ea29a7f94f7b7887a75ad3a7
Ancestor: 18fa8a6f818cbe2838cfe9b1bfa0c5d9c311930c
Platform:
osname=linux
osvers=5.14.0-1049-oem
archname=x86_64-linux-thread-multi
uname='linux oncidium 5.14.0-1049-oem #56-ubuntu smp fri aug 12 10:23:08 utc 2022 x86_64 x86_64 x86_64 gnulinux '
config_args='-Dusethreads -Doptimize=-g -d -Dusedevel -Dcc=ccache gcc -Dld=gcc -DDEBUGGING'
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='gcc'
ccflags ='-D_REENTRANT -D_GNU_SOURCE -fwrapv -DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'
optimize='-g'
cppflags='-D_REENTRANT -D_GNU_SOURCE -fwrapv -DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include'
ccversion=''
gccversion='9.4.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='gcc'
ldflags =' -fstack-protector-strong -L/usr/local/lib'
libpth=/usr/local/lib /usr/lib/x86_64-linux-gnu /usr/lib /usr/lib64
libs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
libc=libc-2.31.so
so=so
useshrplib=false
libperl=libperl.a
gnulibc_version='2.31'
Dynamic Linking:
dlsrc=dl_dlopen.xs
dlext=so
d_dlsymun=undef
ccdlflags='-Wl,-E'
cccdlflags='-fPIC'
lddlflags='-shared -g -L/usr/local/lib -fstack-protector-strong'
Characteristics of this binary (from libperl):
Compile-time options:
DEBUGGING
HAS_TIMES
MULTIPLICITY
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_TRACK_MEMPOOL
PERL_USE_DEVEL
PERL_USE_SAFE_PUTENV
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
Locally applied patches:
uncommitted-changes
b3a0a5e1356f495dc935458a9ee5b38085e130f8
f1886e10a63297209ad9c385b054717c4a089d8b
ebc2efe6583f7cf7ea29a7f94f7b7887a75ad3a7
Built under linux
Compiled at Aug 26 2022 14:32:36
%ENV:
PERLBREW_CONFIGURE_FLAGS="-de -Dcc=ccache\ gcc -Dld=gcc"
PERLBREW_HOME="/home/yorton/.perlbrew"
PERLBREW_MANPATH="/home/yorton/perl5/perlbrew/perls/perl-5.34.1/man"
PERLBREW_PATH="/home/yorton/perl5/perlbrew/bin:/home/yorton/perl5/perlbrew/perls/perl-5.34.1/bin"
PERLBREW_PERL="perl-5.34.1"
PERLBREW_ROOT="/home/yorton/perl5/perlbrew"
PERLBREW_SHELLRC_VERSION="0.88"
PERLBREW_VERSION="0.88"
@INC:
lib
/usr/local/lib/perl5/site_perl/5.37.4/x86_64-linux-thread-multi
/usr/local/lib/perl5/site_perl/5.37.4
/usr/local/lib/perl5/5.37.4/x86_64-linux-thread-multi
/usr/local/lib/perl5/5.37.4