Skip to content

ln panics (unwrap None) on -r with a parentless target (/) #12628

@leeewee

Description

@leeewee

Summary

Running ln -r (--relative) with a destination that has no parent — the root / or the empty string "", taken verbatim via -T — panics. relative_path computes the destination's parent with dst.parent().unwrap(), but Path::parent() is None for a prefix-only/root path, so the .unwrap() aborts (exit 134) before any filesystem operation. GNU instead reports /: cannot overwrite directory and exits 1 (/: cannot overwrite directory for /; failed to create symbolic link '': No such file or directory for "").

Steps to reproduce

$ echo data > /tmp/lnsrc
$ ln -rsfT /tmp/lnsrc /
thread 'main' panicked at src/uu/ln/src/ln.rs:398:26:
called `Option::unwrap()` on a `None` value
$ echo $?
134

Expected behavior

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

$ /usr/bin/ln -rsfT /tmp/lnsrc /
/usr/bin/ln: /: cannot overwrite directory
$ echo $?
1

Actual behavior

uutils panics with Option::unwrap() on a None value and aborts with exit code 134. The crash happens while building the relative source path, before any link or overwrite check, so it short-circuits the error GNU would otherwise report.

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