Skip to content

cp --remove-destination deletes the file when source and dest are the same #13144

Closed

Description

@sylvestre

Reported by @HackingRepo via security advisory GHSA-9p9p-xh9v-6fvx. We don't consider this a security issue, so we're tracking it as a regular bug.

Description
cp --remove-destination a ./a removes the file before detecting that source and destination are the same path, destroying the data.

Repro

$ echo hello > a
$ cp --remove-destination a ./a
cp: cannot stat 'a': No such file or directory
$ cat a
cat: a: No such file or directory      # file is gone

GNU refuses: cp: 'a' and './a' are the same file, leaving a intact.

Expected: detect the same-file case and error out without deleting.
Actual: the file is unlinked, then the copy fails — data loss.

Activity

  1. LoukasPap commented on Jun 28, 2026

    @LoukasPap
    Contributor

    This is solved here: #13135

  2. cakebaker commented on Jul 1, 2026

    @cakebaker
    Contributor

    @HackingRepo thanks for the hint!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions