Skip to content

Commit a71385d

Browse files
committed
perl5db: use a lexical copy of $DB::sub inside DB::sub
When perl calls DB::sub in the debugger, it sets $DB::sub to the sub being called. If we trigger any other subs to get called somewhere inside DB::sub, this could cause DB::sub to be called again, overwriting the global. Perl won't call DB::sub for any sub calls within the DB namespace, but we could inadvertently trigger this via a sub override or magic, like overloads. Create a copy of the global value in a lexical to use inside the sub, to avoid it ever getting overwritten.
1 parent 148136c commit a71385d

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

lib/perl5db.pl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4434,6 +4434,11 @@ sub _print_frame_message {
44344434
sub DB::sub {
44354435
my ( $al, $ret, @ret ) = "";
44364436

4437+
# keep a lexical copy, rather than relying on the global. the global
4438+
# variable could be overwritten if something inside this sub triggers
4439+
# another sub call, running DB::sub again. overloads for example.
4440+
my $sub = $DB::sub;
4441+
44374442
# We stack the stack pointer and then increment it to protect us
44384443
# from a situation that might unwind a whole bunch of call frames
44394444
# at once. Localizing the stack pointer means that it will automatically
@@ -4568,6 +4573,7 @@ sub DB::sub {
45684573
} ## end sub _sub
45694574

45704575
sub lsub : lvalue {
4576+
my $sub = $DB::sub;
45714577

45724578
# We stack the stack pointer and then increment it to protect us
45734579
# from a situation that might unwind a whole bunch of call frames

0 commit comments

Comments
 (0)