fix: enforce parent-dir permission check on sysopen O_CREAT#401
Draft
Koan-Bot wants to merge 1 commit into
Draft
fix: enforce parent-dir permission check on sysopen O_CREAT#401Koan-Bot wants to merge 1 commit into
Koan-Bot wants to merge 1 commit into
Conversation
The `elsif` branch in `__sysopen`'s permission check that verified
parent-directory write+execute permission for new file creation was
unreachable dead code. O_CREAT set `contents = ''` before the check,
and the ENOENT guard returned early when contents was undef, so
`defined $mock_file->{'contents'}` was always true at the permission
check.
Fix: capture `$is_new` flag before O_CREAT modifies contents and use
it to route the permission check. Now `sysopen($fh, $path, O_WRONLY|O_CREAT)`
in a read-only directory correctly returns EACCES, matching `open()`
behavior.
Closes cpan-authors#329
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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
Fix dead
elsifbranch in__sysopenthat silently skipped parent-directory permission checks when creating new files viaO_CREAT.Why
The permission check at the end of
__sysopentesteddefined $mock_file->{'contents'}to distinguish new vs. existing files. But O_CREAT already setcontents = ''earlier in the function, and the ENOENT guard returned early when contents was undef — so theelsifbranch that checks parent-dir write+execute was unreachable. This meantsysopen($fh, '/protected/new', O_WRONLY|O_CREAT)would succeed in a read-only directory underset_user(), while the equivalentopen($fh, '>', '/protected/new')correctly returned EACCES.Issue #329 identified the root cause; issue #330 tracks the broader duplication.
How
Capture
my $is_new = !defined $mock_file->{'contents'}before the O_CREAT block modifies contents. Use$is_new(notdefined contents) to route the permission check: existing files check file-level perms, new files check parent-dir write+execute.Testing
t/perms.t: sysopen O_CREAT in read-only vs. writable parent dir, and sysopen on existing file with file-level perm checkCloses #329
🤖 Generated with Claude Code
Quality Report
Changes: 9 files changed, 118 insertions(+), 1176 deletions(-)
Code scan: clean
Tests: passed (OK)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline