From fae1043627b55d86202495aa8fab25fd03dd19d6 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 24 Oct 2023 21:40:36 +0300 Subject: [PATCH] cp fix --- LICENSE | 13 +++++++++++++ coreutils/cp.c | 3 +++ 2 files changed, 16 insertions(+) diff --git a/LICENSE b/LICENSE index e69de29..456c488 100644 --- a/LICENSE +++ b/LICENSE @@ -0,0 +1,13 @@ + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + Version 2, December 2004 + + Copyright (C) 2004 Sam Hocevar + + Everyone is permitted to copy and distribute verbatim or modified + copies of this license document, and changing it is allowed as long + as the name is changed. + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. You just DO WHAT THE FUCK YOU WANT TO. diff --git a/coreutils/cp.c b/coreutils/cp.c index db3b79f..ad964dc 100644 --- a/coreutils/cp.c +++ b/coreutils/cp.c @@ -81,6 +81,9 @@ int copy(int mode, const char *src, const char *dst) { if (new_path == NULL) goto CLOSE; + if (!strcmp(new_path, src) || !strcmp(new_path + 2, src)) + goto CLOSE; + ofd = open(new_path, O_CREAT | O_TRUNC | O_RDWR, mode); if (ofd < 0) goto CLOSE;