fix: extract _check_open_perms, fix dead elsif in __sysopen#337
Draft
toddr-bot wants to merge 1 commit intocpan-authors:mainfrom
Draft
fix: extract _check_open_perms, fix dead elsif in __sysopen#337toddr-bot wants to merge 1 commit intocpan-authors:mainfrom
toddr-bot wants to merge 1 commit intocpan-authors:mainfrom
Conversation
The permission-check pattern was copy-pasted three times across _io_file_mock_open, __open, and __sysopen, with a bug in the __sysopen copy: O_CREAT populated contents before the permission check, making the parent-dir write-permission elsif unreachable. Extract a shared _check_open_perms() helper that takes an $is_new flag (captured before O_CREAT logic runs) to correctly route between file-permission and parent-directory-permission checks. Add a regression test proving sysopen(O_CREAT) into a read-only parent directory now returns EACCES. Closes cpan-authors#329 Closes cpan-authors#330 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
4adac00 to
9a3c1ec
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Extract a shared
_check_open_perms()helper and fix the deadelsifbranch in__sysopenthat silently bypassed parent-directory write-permission enforcement.Why
The permission-check block was copy-pasted three times across
_io_file_mock_open,__open, and__sysopen. In__sysopen, O_CREAT populatedcontentsbefore the permission check ran, making the parent-direlsifunreachable dead code. This meantsysopen($fh, '/protected/new', O_WRONLY|O_CREAT)would succeed in a restricted directory whileopen($fh, '>', '/protected/new')correctly returned EACCES.How
my $is_new = !defined $mock_file->{'contents'}before O_CREAT logic runs_check_open_perms($mock_file, $abs_path, $rw, $is_new, $func_name, @args)that encapsulates the existing-file vs new-file permission routingTesting
t/perms.t: verifiessysopen(O_CREAT)into a 0555 parent dir returns EACCESfh-ref-leak.tfailure)Closes #329
Closes #330
🤖 Generated with Claude Code
Quality Report
Changes: 2 files changed, 66 insertions(+), 61 deletions(-)
Code scan: clean
Tests: failed (FAILED)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline