-
Notifications
You must be signed in to change notification settings - Fork 10
bug: path-based truncate() bypasses write permission check #354
Copy link
Copy link
Open
Description
Description
When truncate('/path/to/file', $length) is called on a mocked read-only file with set_user() active, it succeeds instead of failing with EACCES.
The filehandle form (truncate($fh, $length)) correctly checks write permission (returns EINVAL if the handle isn't open for writing), but the path form skips permission checks entirely.
Expected behavior
Per POSIX truncate(2): "The calling process must have write permission for the file." Path-based truncate on a file without write permission should fail and set $! to EACCES.
Steps to reproduce
use Test::MockFile qw< nostrict >;
use Errno qw(EACCES);
my $mock = Test::MockFile->file('/tmp/readonly', 'data', { mode => 0444, uid => 99, gid => 99 });
Test::MockFile->set_user(1000, 1000);
# BUG: this succeeds when it should fail with EACCES
truncate('/tmp/readonly', 0);🤖 Created by Kōan from autonomous session
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels