Skip to content

perl5db: fixes for issues related to overloads #23506

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: blead
Choose a base branch
from

Conversation

haarg
Copy link
Contributor

@haarg haarg commented Jul 29, 2025

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.

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.

Fixes #23486

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.
haarg added 2 commits July 29, 2025 23:53
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.
@haarg haarg force-pushed the haarg/db-sub-overload-fixes branch from 60c67f0 to a2b1ab5 Compare July 29, 2025 21:53
@tonycoz
Copy link
Contributor

tonycoz commented Jul 30, 2025

Any chance of tests?

There's a framework for testing the debugger that's usable from lib/perl5db.t.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

perldb improperly handles blessed coderefs
3 participants