Deleting a directory with the same name as a shortcut deletes everything in CWD
Ken Brown
kbrown@cornell.edu
Mon Aug 8 23:29:21 GMT 2022
On 8/8/2022 7:56 AM, Christian Franke wrote:
> Testcase:
>> $ ls -a
> . ..
>> $ touch link.lnk file.txt
>> $ ls -a
> . .. file.txt link.lnk
>> $ stat -c %F link.lnk
> regular empty file
>> $ stat -c %F link
> directory
This happens because symlink_info::check returns -1 instead of 0 when called on
"link". The main loop over suffixes finds and rejects link.lnk but then leaves
"res" as -1 when it continues looping. The following patch fixes the problem:
--- a/winsup/cygwin/path.cc
+++ b/winsup/cygwin/path.cc
@@ -3422,6 +3422,7 @@ restart:
{
fileattr = INVALID_FILE_ATTRIBUTES;
set_error (ENOENT);
+ res = 0;
continue;
}
It's possible that a better fix would be to set res = 0 at the beginning of each
iteration of the loop, but I'll have to study the code more carefully before I'm
sure of that. Also, the comment preceding symlink_info::check needs to be fixed
to correctly indicate what a negative return value means. I'll look at all this
more carefully tomorrow if no one beats me to it.
Ken
More information about the Cygwin
mailing list