mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
Userland: Fix overly-eager loop detection in cp (#4368)
The bug is that if you try to cp DIR_A to DIR_B where DIR_A and DIR_B have the same parent directory and DIR_A's name is a prefix of DIR_B (e.g. foo -> foo2, bar -> barbar), it thinks that it's a subdirectory (since it checks if DIR_A's realpath is a prefix of DIR_B's realpath). The easiest solution is to put a path delimiter at the end before the comparison, since you can't have a / in the middle of a directory name. For example if DIR_A is /home/anon/foo and DIR_B is /home/anon/foo2, then DIR_A's realpath is a prefix of DIR_B's realpath even though DIR_B is not inside DIR_A.
This commit is contained in:
parent
a3bcff0db8
commit
9453032bf6
Notes:
sideshowbarker
2024-07-19 00:57:39 +09:00
Author: https://github.com/ccapitalK Commit: https://github.com/SerenityOS/serenity/commit/9453032bf69 Pull-request: https://github.com/SerenityOS/serenity/pull/4368 Issue: https://github.com/SerenityOS/serenity/issues/4365
1 changed files with 2 additions and 0 deletions
|
@ -181,7 +181,9 @@ bool copy_directory(String src_path, String dst_path)
|
|||
}
|
||||
|
||||
String src_rp = Core::File::real_path_for(src_path);
|
||||
src_rp = String::format("%s/", src_rp.characters());
|
||||
String dst_rp = Core::File::real_path_for(dst_path);
|
||||
dst_rp = String::format("%s/", dst_rp.characters());
|
||||
|
||||
if (!dst_rp.is_empty() && dst_rp.starts_with(src_rp)) {
|
||||
fprintf(stderr, "cp: Cannot copy %s into itself (%s)\n",
|
||||
|
|
Loading…
Reference in a new issue