Skip to content

cp panics (unwrap Err) on --attributes-only into an unwritable destination #12624

@leeewee

Description

@leeewee

Summary

cp --attributes-only SRC DEST, where the destination's parent directory is not writable (e.g. mode 555), makes uutils cp open the destination with create(true) and .unwrap() the result. The open fails with EACCES (PermissionDenied), so the unwrap panics and the process aborts with exit code 134. GNU cp reports the error and exits 1.

Steps to reproduce

$ mkdir -p /tmp/cptest/ro && cd /tmp/cptest && echo hi > s.txt && chmod 555 ro
$ cp --attributes-only s.txt ro/n.txt
thread 'main' panicked at src/uu/cp/src/cp.rs:2389:18:
called `Result::unwrap()` on an `Err` value: Os { code: 13, kind: PermissionDenied, message: "Permission denied" }
$ echo $?
134

Expected behavior

Match GNU: report the error and exit non-zero without crashing.

$ /usr/bin/cp --attributes-only s.txt ro/n.txt
/usr/bin/cp: cannot create regular file 'ro/n.txt': Permission denied
$ echo $?
1

Actual behavior

uutils cp panics (Result::unwrap() on an Err) and the process aborts with exit code 134, printing a Rust panic message instead of a diagnostic.

This is an I/O-failure path — distinct from the dev-full write-error family; the failure is on the destination open, not on a write. The same site can fire on other open errors (e.g. EROFS on a read-only filesystem).

Found by our static analysis tooling.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions