From 352de39c3474fdb73570121820b493bd81a73bb5 Mon Sep 17 00:00:00 2001 From: Jeremy Drake Date: Sat, 29 May 2021 11:48:11 -0700 Subject: [PATCH 2/2] Cygwin: tweak handling of native symlinks from chdir The new GetFinalPathNameW handling for native symlinks in inner path components is disabled in chdir, allowing native processes to see their cwd potentially including native symlinks, rather than dereferencing them. --- winsup/cygwin/path.cc | 5 +++-- winsup/cygwin/path.h | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc index e62f8fe2b..130926cbc 100644 --- a/winsup/cygwin/path.cc +++ b/winsup/cygwin/path.cc @@ -751,7 +751,7 @@ path_conv::check (const char *src, unsigned opt, if (error) return; - sym.pc_flags = pc_flags; + sym.pc_flags = pc_flags | (opt & PC_NO_NATIVE_SYM_INNER); if (!dev.exists ()) { @@ -3480,6 +3480,7 @@ restart: goto file_not_symlink; } #endif /* __i386__ */ + if (!(pc_flags & PC_NO_NATIVE_SYM_INNER)) { PWCHAR fpbuf = tp.w_get (); DWORD ret; @@ -3704,7 +3705,7 @@ chdir (const char *in_dir) /* Convert path. PC_NONULLEMPTY ensures that we don't check for NULL/empty/invalid again. */ - path_conv path (in_dir, PC_SYM_FOLLOW | PC_POSIX | PC_NONULLEMPTY); + path_conv path (in_dir, PC_SYM_FOLLOW | PC_POSIX | PC_NONULLEMPTY | PC_NO_NATIVE_SYM_INNER); if (path.error) { set_errno (path.error); diff --git a/winsup/cygwin/path.h b/winsup/cygwin/path.h index adb0ca11f..d3b14a40c 100644 --- a/winsup/cygwin/path.h +++ b/winsup/cygwin/path.h @@ -59,6 +59,7 @@ enum pathconv_arg PC_KEEP_HANDLE = _BIT (12), /* keep handle for later stat calls */ PC_NO_ACCESS_CHECK = _BIT (13), /* helper flag for error check */ PC_SYM_NOFOLLOW_DIR = _BIT (14), /* don't follow a trailing slash */ + PC_NO_NATIVE_SYM_INNER = _BIT (15), /* skip native symlink inner handling */ PC_DONT_USE = _BIT (31) /* conversion to signed happens. */ }; -- 2.31.1.windows.1