Skip to content

fix: make _check() re-entrant safe for nested mock callbacks#74

Draft
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Koan-Bot:koan.atoomic/fix-check-reentrant
Draft

fix: make _check() re-entrant safe for nested mock callbacks#74
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Koan-Bot:koan.atoomic/fix-check-reentrant

Conversation

@Koan-Bot
Copy link
Copy Markdown
Contributor

@Koan-Bot Koan-Bot commented Apr 2, 2026

What

Save and restore $_last_call_for around callback dispatch in _check() to prevent re-entrant calls from corrupting the filename cache.

Why

When a mock_all_from_stat callback (or any mock callback) invokes another mocked file test, _check() is called re-entrantly. The inner call overwrites $_last_call_for, corrupting the stacked -X _ filename context for the outer call. This could cause stacked ops to test the wrong filename — a subtle correctness issue in complex mock scenarios.

How

  • Save $_last_call_for before dispatching the callback
  • After the callback, set the cache to the current call's filename (string) or restore the saved value (filehandle ref — improvement over previous undef clobber from GH #179)
  • Added t/reentrant-check.t with 9 tests covering: re-entrant callbacks with stacked ops, and mock_all_from_stat with nested file tests

Testing

  • New test t/reentrant-check.t — 9 tests, all pass
  • Full suite: 1259 tests pass, 0 failures

Closes #68

🤖 Generated with Claude Code

Save $_last_call_for before dispatching the user callback and restore it
(instead of clobbering with undef) when the file argument is a reference.
This prevents re-entrant _check() calls — e.g. mock_all_from_stat
callbacks that invoke other mocked file tests — from corrupting the
filename cache used by stacked -X _ operations.

Also improves the filehandle-ref case (GH #179): instead of setting the
cache to undef, we restore the pre-callback value so that a valid
filename from before the filehandle call remains available for subsequent
stacked ops.

Closes cpan-authors#68

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

Security: _check() re-entrancy corrupts file cache used by stacked file tests

1 participant