Skip to content

fix: enforce write permission check on path-based truncate#402

Draft
Koan-Bot wants to merge 1 commit into
cpan-authors:mainfrom
atoomic:koan.atoomic/fix-truncate-path-perms
Draft

fix: enforce write permission check on path-based truncate#402
Koan-Bot wants to merge 1 commit into
cpan-authors:mainfrom
atoomic:koan.atoomic/fix-truncate-path-perms

Conversation

@Koan-Bot
Copy link
Copy Markdown
Contributor

What

Add write permission check for path-based truncate() when set_user() is active.

Why

POSIX truncate(2) requires write permission on the file. The filehandle form already checked via the handle's write flag, but path-based truncate skipped permission checks entirely — allowing truncate('/readonly-file', 0) to succeed under set_user().

How

Call _check_perms($mock, 2) for path-based calls (non-ref $file_or_fh) when $_mock_uid is defined. Returns EACCES on denial; root bypasses as expected.

Testing

Three new subtests in t/truncate.t:

  • Write denied (mode 0444, non-owner) → EACCES
  • Write allowed (mode 0644, owner) → succeeds
  • Root bypass (mode 0000, uid 0) → succeeds

Full test suite passes.

Closes #354

🤖 Generated with Claude Code

Path-based truncate() bypassed write permission checks when set_user()
was active. POSIX truncate(2) requires write permission on the file,
but only the filehandle form was checking (via the handle's write flag).

Add _check_perms($mock, 2) for path-based calls when $_mock_uid is set,
returning EACCES on denial. Root (uid 0) bypasses as expected.

Closes cpan-authors#354

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: path-based truncate() bypasses write permission check

1 participant