Skip to content

cp: --backup=nil and --backup --suffix= silently skip backup creation #13143

Description

@sylvestre

Reported by @HackingRepo via security advisory GHSA-x6wh-gw25-4rjx. We don't consider this a security issue, so we're tracking it as a regular bug.

Description
cp fails to create a backup in two cases where GNU does, risking silent loss of the overwritten file's previous contents.

Repro

$ echo data > a; echo dest > b
$ cp --backup=nil --suffix= a b      # uu: no b~ created
$ cp --backup --suffix= a b          # uu: no b~ created

GNU creates b~ in both cases (nil is the existing backup control, and --backup with an empty --suffix falls back to the default ~).

Expected: a backup b~ is created before b is overwritten.
Actual: no backup; previous contents of b are lost.

Follow-up to the earlier --suffix-alone backup fix; the same guard is still bypassable via --backup=nil and an empty suffix. A test should cover both forms.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    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