Skip to content

Commit b010c9d

Browse files
committed
perl5db: only check sub names for non-references
DB::sub can be called by perl giving it either a name (if it can be determined) or a code ref. There is special handling for AUTOLOAD subs and threads::new. This could only be happen when given the name of the sub, so there is no need to do these checks if given a reference. Additionally, a reference could be an object, which could have overloads. Those overloads could fail or otherwise complicate the normal operation of DB::sub. Add a ref check to the sub given to DB::sub to avoid these issues.
1 parent a71385d commit b010c9d

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lib/perl5db.pl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4460,13 +4460,13 @@ sub DB::sub {
44604460
# Whether or not the autoloader was running, a scalar to put the
44614461
# sub's return value in (if needed), and an array to put the sub's
44624462
# return value in (if needed).
4463-
if ($sub eq 'threads::new' && $ENV{PERL5DB_THREADED}) {
4463+
if (ref $sub && $sub eq 'threads::new' && $ENV{PERL5DB_THREADED}) {
44644464
print "creating new thread\n";
44654465
}
44664466

44674467
# If the last ten characters are '::AUTOLOAD', note we've traced
44684468
# into AUTOLOAD for $sub.
4469-
if ( length($sub) > 10 && substr( $sub, -10, 10 ) eq '::AUTOLOAD' ) {
4469+
if ( ref $sub && length($sub) > 10 && substr( $sub, -10, 10 ) eq '::AUTOLOAD' ) {
44704470
no strict 'refs';
44714471
$al = " for $$sub" if defined $$sub;
44724472
}
@@ -4601,13 +4601,13 @@ sub lsub : lvalue {
46014601
# sub's return value in (if needed), and an array to put the sub's
46024602
# return value in (if needed).
46034603
my ( $al, $ret, @ret ) = "";
4604-
if ($sub =~ /^threads::new$/ && $ENV{PERL5DB_THREADED}) {
4604+
if ( ref $sub && $sub =~ /^threads::new$/ && $ENV{PERL5DB_THREADED}) {
46054605
print "creating new thread\n";
46064606
}
46074607

46084608
# If the last ten characters are C'::AUTOLOAD', note we've traced
46094609
# into AUTOLOAD for $sub.
4610-
if ( length($sub) > 10 && substr( $sub, -10, 10 ) eq '::AUTOLOAD' ) {
4610+
if ( ref $sub && length($sub) > 10 && substr( $sub, -10, 10 ) eq '::AUTOLOAD' ) {
46114611
$al = " for $$sub";
46124612
}
46134613

0 commit comments

Comments
 (0)