Skip to content

bug: path-based truncate() bypasses write permission check #354

@toddr-bot

Description

@toddr-bot

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions