[git commit] cp: fix `cp -aT` overwriting symlink to directories
Denys Vlasenko
vda.linux at googlemail.com
Tue Oct 7 08:05:08 UTC 2025
commit: https://git.busybox.net/busybox/commit/?id=a0017a5b5038b3f803ece9140099410c8d4ed4b1
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master
busybox cp refuses to overwrite another symlink to a directory due to
an incorrect stat() call that should be lstat(). When using -T, we want
to consider the target argument directly without resolving symlinks.
function old new delta
cp_main 496 514 +18
Signed-off-by: Dominique Martinet <dominique.martinet at atmark-techno.com>
Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
coreutils/cp.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/coreutils/cp.c b/coreutils/cp.c
index ee40af50b..961de5b42 100644
--- a/coreutils/cp.c
+++ b/coreutils/cp.c
@@ -215,7 +215,8 @@ int cp_main(int argc, char **argv)
(flags & FILEUTILS_DEREFERENCE) ? stat : lstat);
if (s_flags < 0) /* error other than ENOENT */
return EXIT_FAILURE;
- d_flags = cp_mv_stat(last, &dest_stat);
+ d_flags = cp_mv_stat2(last, &dest_stat,
+ (flags & FILEUTILS_NO_TARGET_DIR) ? lstat : stat);
if (d_flags < 0) /* error other than ENOENT */
return EXIT_FAILURE;
More information about the busybox-cvs
mailing list