fix: enforce write permission on path-based truncate()#355
Draft
toddr-bot wants to merge 2 commits intocpan-authors:mainfrom
Draft
fix: enforce write permission on path-based truncate()#355toddr-bot wants to merge 2 commits intocpan-authors:mainfrom
toddr-bot wants to merge 2 commits intocpan-authors:mainfrom
Conversation
Path-based truncate() on a read-only mocked file succeeds when it should fail with EACCES. This test proves the vulnerability before the fix. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
POSIX truncate(2) requires write permission on the file when called by path. The mocked truncate only checked permission for the filehandle form (EINVAL if not open for writing) but allowed path-based truncate to succeed on read-only files. Add _check_perms($mock, 2) for the path case. 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
Add write permission check for path-based
truncate()on mocked files.Why
POSIX truncate(2) requires write permission on the target file. The mocked implementation only enforced this for the filehandle form (EINVAL if not open for writing) but allowed path-based truncate to silently succeed on read-only files when
set_user()was active. Fixes #354.How
Added
_check_perms($mock, 2)in theelsebranch (path-based call) of__truncate, returning EACCES on failure. This mirrors how other operations (chmod, chown) enforce permission checks. Root bypass is handled by_check_permsitself.Testing
🤖 Generated with Claude Code
Quality Report
Changes: 2 files changed, 56 insertions(+), 1 deletion(-)
Code scan: clean
Tests: failed (4 Failed, 94 test)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline