Skip to content

cp panics (unwrap None) on --parents with a source path ending in .. #12626

@leeewee

Description

@leeewee

Summary

cp --parents -r SRC DEST, where the source path's final component is .., makes uutils cp call root.file_name() — which returns None for such a path — and then .unwrap() it. The unwrap panics and the process aborts with exit code 134. GNU cp reports a normal error (cannot create directory … File exists) and exits 1.

Steps to reproduce

$ mkdir -p /tmp/cpp/src/sub && echo x > /tmp/cpp/src/sub/f && mkdir -p /tmp/cpp/d && cd /tmp/cpp
$ cp --parents -r 'src/sub/..' d
thread 'main' panicked at src/uu/cp/src/copydir.rs:575:49:
called `Option::unwrap()` on a `None` value
$ echo $?
134

Expected behavior

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

$ /usr/bin/cp --parents -r 'src/sub/..' d
/usr/bin/cp: cannot create directory 'd/src/sub/..': File exists
$ echo $?
1

Actual behavior

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

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