Root directory being a junction fools realpath()
Corinna Vinschen
corinna-cygwin@cygwin.com
Mon Feb 15 12:25:38 GMT 2021
On Feb 14 12:56, David Macek via Cygwin-developers wrote:
> Greetings.
>
> I think I found a way to fool Cygwin into misplacing its root
> directory. Given recent Cygwin with GCC and a simple test program:
>
> ```
> #include <stdio.h>
> #include <limits.h>
> #include <stdlib.h>
> int main() {
> char real[PATH_MAX];
> realpath("/", real);
> printf("/ -> %s\n", real);
> return 0;
> }
> ```
>
> ... compiled with:
>
> $ gcc -D_DEFAULT_SOURCE -o new.exe -Wall -Wextra -std=c11 new.c
>
> ... and my set-up with a junction (`mklink /j link target`) realpath()
> result is dependent on which path I use to invoke the Cygwin root
> process:
>
> > dir C:\ | findstr cygwin64
> 10. 02. 2021 12:13 <DIR> cygwin64
>
> > dir D:\ | findstr cygwin64
> 14. 02. 2021 12:19 <JUNCTION> cygwin64 [C:\cygwin64]
>
> > C:\cygwin64\bin\bash -lc /cygdrive/w/new
> / -> /
>
> > D:\cygwin64\bin\bash -lc /cygdrive/w/new
> / -> /cygdrive/c/cygwin64
This isn't realpath's fault. You're circumventing the mount point
handling which is automated in terms of /, depending on the path
returned from GetModuleFileNameW for the Cygwin DLL. Since you're
calling D:\cygwin64\bin\bash the dir returned from GetModuleFileNameW is
D:\cygwin64\bin, thus root is D:\cygwin64.
However, junctions are treated as symlinks in Cygwin. Thus the result
you see above.
Corinna
More information about the Cygwin-developers
mailing list