Skip to content

fix: add parent-directory permission checks to rename()#340

Draft
toddr-bot wants to merge 1 commit intocpan-authors:mainfrom
toddr-bot:koan.toddr.bot/fix-rename-perms
Draft

fix: add parent-directory permission checks to rename()#340
toddr-bot wants to merge 1 commit intocpan-authors:mainfrom
toddr-bot:koan.toddr.bot/fix-rename-perms

Conversation

@toddr-bot
Copy link
Copy Markdown
Collaborator

@toddr-bot toddr-bot commented Mar 31, 2026

What

Add missing write+execute permission checks on both parent directories in rename().

Why

POSIX rename(2) requires write+execute on both the source and destination parent directories. Every other directory-modifying operation (unlink, mkdir, rmdir) already enforced this via _check_parent_perms(), but rename was missing the check entirely. With set_user() active, rename('/protected/src/file', '/dst/file') would succeed even when the source parent was 0555 — now it correctly returns EACCES.

How

Added _check_parent_perms($mock_old->{'path'}, 2|1) and _check_parent_perms($mock_new->{'path'}, 2|1) checks after the self-rename no-op shortcut, following the same pattern used by unlink, mkdir, and rmdir.

Testing

  • 3 new test cases in t/rename.t: source parent read-only (EACCES), dest parent read-only (EACCES), both parents writable (success)
  • Full suite: 1594 tests pass (only pre-existing fh-ref-leak.t failure)

🤖 Generated with Claude Code


Quality Report

Changes: 2 files changed, 55 insertions(+), 1 deletion(-)

Code scan: clean

Tests: failed (4 Failed, 94 test)

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

POSIX rename(2) requires write+execute permission on both the source
and destination parent directories. All other directory-modifying
operations (unlink, mkdir, rmdir) already enforced this via
_check_parent_perms(), but rename was missing the check entirely.

With set_user() active, rename('/protected/src/f', '/dst/f') would
succeed even when the source parent was read-only — now it correctly
returns EACCES.

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.

1 participant