Skip to content

fix: make __sysopen parent-dir permission check reachable#334

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

fix: make __sysopen parent-dir permission check reachable#334
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
atoomic:koan.atoomic/fix-sysopen-permission-check

Conversation

@Koan-Bot
Copy link
Copy Markdown
Contributor

What

Fixes dead elsif branch in __sysopen that silently bypassed parent-directory permission enforcement when creating files via O_CREAT.

Why

The O_CREAT block initialized $mock_file->{'contents'} = '' before the permission check, making the "defined contents" condition always true. The elsif for parent-dir write+execute was unreachable. This meant sysopen($fh, '/protected/new', O_WRONLY|O_CREAT) with set_user() would succeed even in a read-only parent directory, while the equivalent open($fh, '>', '/protected/new') correctly returned EACCES.

How

Save $is_new = !defined $mock_file->{'contents'} before the O_CREAT block modifies contents. Use $is_new in the permission check instead of re-testing defined $mock_file->{'contents'}. Also replaced inline _throw_autodie calls with _maybe_throw_autodie in the same block (#331 partial).

Testing

  • Added subtest in t/perms.t verifying sysopen O_CREAT is denied in a 0555 parent dir and allowed in a 0755 parent dir
  • All 102 sysopen.t tests pass, all 19 perms.t tests pass

Closes #329

🤖 Generated with Claude Code

…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>
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.

bug: Dead elsif branch in __sysopen permission check silently bypasses parent-dir write-permission enforcement

1 participant