fix: make __sysopen parent-dir permission check reachable#334
Draft
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Draft
fix: make __sysopen parent-dir permission check reachable#334Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Conversation
…thors#329) The elsif branch checking parent-directory write+execute permissions for new file creation via sysopen(O_CREAT) was dead code: O_CREAT initialized contents to '' before the permission block, making the "defined contents" condition always true. Fix: save $is_new flag before O_CREAT modifies contents, then use it instead of re-checking contents in the permission block. Also replaced inline _throw_autodie calls with _maybe_throw_autodie. 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
Fixes dead
elsifbranch in__sysopenthat silently bypassed parent-directory permission enforcement when creating files viaO_CREAT.Why
The
O_CREATblock initialized$mock_file->{'contents'} = ''before the permission check, making the "defined contents" condition always true. Theelsiffor parent-dir write+execute was unreachable. This meantsysopen($fh, '/protected/new', O_WRONLY|O_CREAT)withset_user()would succeed even in a read-only parent directory, while the equivalentopen($fh, '>', '/protected/new')correctly returnedEACCES.How
Save
$is_new = !defined $mock_file->{'contents'}before theO_CREATblock modifies contents. Use$is_newin the permission check instead of re-testingdefined $mock_file->{'contents'}. Also replaced inline_throw_autodiecalls with_maybe_throw_autodiein the same block (#331 partial).Testing
t/perms.tverifying sysopen O_CREAT is denied in a 0555 parent dir and allowed in a 0755 parent dirCloses #329
🤖 Generated with Claude Code