Skip to content

Commit

Permalink
Merge pull request #2594 from jeremyd2019/msys2-runtime-native-inner-…
Browse files Browse the repository at this point in the history
…links

msys2-runtime: add patch for native inner links
  • Loading branch information
lazka authored Aug 2, 2021
2 parents e9fb14a + 8570fac commit c88ba5c
Show file tree
Hide file tree
Showing 4 changed files with 225 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
From 64a769a67a94d8d6f1dc262a33e50fccbb404d23 Mon Sep 17 00:00:00 2001
From: Jeremy Drake <cygwin@jdrake.com>
Date: Sat, 29 May 2021 13:17:08 -0700
Subject: [PATCH 46/N] Revert "Cygwin: Handle virtual drives as non-symlinks"

This reverts commit c8949d04001e3dbc03651475b6cd1c5623400835.
---
winsup/cygwin/path.cc | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc
index 85605cf..68b0a8d 100644
--- a/winsup/cygwin/path.cc
+++ b/winsup/cygwin/path.cc
@@ -3665,9 +3665,14 @@ restart:

subst X: C:\foo\bar

- Treat it as a normal file. */
+ Treat it like a symlink. This is required to tell an
+ lstat caller that the "drive" is actually pointing
+ somewhere else, thus, it's a symlink in POSIX speak. */
if (upath.Length == 14) /* \??\X:\ */
- goto file_not_symlink;
+ {
+ fileattr &= ~FILE_ATTRIBUTE_DIRECTORY;
+ path_flags |= PATH_SYMLINK;
+ }
/* For final paths differing in inner path components return
length as negative value. This informs path_conv::check
to skip realpath handling on the last path component. */
--
2.32.0.windows.2

Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
From 54d3664fe0e78823128ea39ffff8a22b52a1e71a Mon Sep 17 00:00:00 2001
From: Jeremy Drake <cygwin@jdrake.com>
Date: Sat, 29 May 2021 11:48:11 -0700
Subject: [PATCH 47/N] Cygwin: respect PC_SYM_FOLLOW and PC_SYM_NOFOLLOW_REP
with inner links.

The new GetFinalPathNameW handling for native symlinks in inner path
components is disabled if caller doesn't want to follow symlinks, or
doesn't want to follow reparse points.
---
winsup/cygwin/path.cc | 86 ++++++++++++++++++++++---------------------
1 file changed, 44 insertions(+), 42 deletions(-)

diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc
index 68b0a8d..67124bb 100644
--- a/winsup/cygwin/path.cc
+++ b/winsup/cygwin/path.cc
@@ -723,9 +723,10 @@ path_conv::check (const char *src, unsigned opt,
int symlen = 0;

/* Make sure to check certain flags on last component only. */
- for (unsigned pc_flags = opt & (PC_NO_ACCESS_CHECK | PC_KEEP_HANDLE);
+ for (unsigned pc_flags = opt & (PC_NO_ACCESS_CHECK | PC_KEEP_HANDLE
+ | PC_SYM_FOLLOW | PC_SYM_NOFOLLOW_REP);
;
- pc_flags = 0)
+ pc_flags = opt & (PC_SYM_FOLLOW | PC_SYM_NOFOLLOW_REP))
{
const suffix_info *suff;
char *full_path;
@@ -3640,48 +3641,49 @@ restart:
goto file_not_symlink;
}
#endif /* __i386__ */
- {
- PWCHAR fpbuf = tp.w_get ();
- DWORD ret;
+ if ((pc_flags & (PC_SYM_FOLLOW | PC_SYM_NOFOLLOW_REP)) == PC_SYM_FOLLOW)
+ {
+ PWCHAR fpbuf = tp.w_get ();
+ DWORD ret;

- ret = GetFinalPathNameByHandleW (h, fpbuf, NT_MAX_PATH, 0);
- if (ret)
- {
- UNICODE_STRING fpath;
+ ret = GetFinalPathNameByHandleW (h, fpbuf, NT_MAX_PATH, 0);
+ if (ret)
+ {
+ UNICODE_STRING fpath;

- RtlInitCountedUnicodeString (&fpath, fpbuf, ret * sizeof (WCHAR));
- fpbuf[1] = L'?'; /* \\?\ --> \??\ */
- if (!RtlEqualUnicodeString (&upath, &fpath, !!ci_flag))
- {
- issymlink = true;
- /* upath.Buffer is big enough and unused from this point on.
- Reuse it here, avoiding yet another buffer allocation. */
- char *nfpath = (char *) upath.Buffer;
- sys_wcstombs (nfpath, NT_MAX_PATH, fpbuf);
- res = posixify (nfpath);
-
- /* If the incoming path consisted of a drive prefix only,
- we just handle a virtual drive, created with, e.g.
-
- subst X: C:\foo\bar
-
- Treat it like a symlink. This is required to tell an
- lstat caller that the "drive" is actually pointing
- somewhere else, thus, it's a symlink in POSIX speak. */
- if (upath.Length == 14) /* \??\X:\ */
- {
- fileattr &= ~FILE_ATTRIBUTE_DIRECTORY;
- path_flags |= PATH_SYMLINK;
- }
- /* For final paths differing in inner path components return
- length as negative value. This informs path_conv::check
- to skip realpath handling on the last path component. */
- else
- res = -res;
- break;
- }
- }
- }
+ RtlInitCountedUnicodeString (&fpath, fpbuf, ret * sizeof (WCHAR));
+ fpbuf[1] = L'?'; /* \\?\ --> \??\ */
+ if (!RtlEqualUnicodeString (&upath, &fpath, !!ci_flag))
+ {
+ issymlink = true;
+ /* upath.Buffer is big enough and unused from this point on.
+ Reuse it here, avoiding yet another buffer allocation. */
+ char *nfpath = (char *) upath.Buffer;
+ sys_wcstombs (nfpath, NT_MAX_PATH, fpbuf);
+ res = posixify (nfpath);
+
+ /* If the incoming path consisted of a drive prefix only,
+ we just handle a virtual drive, created with, e.g.
+
+ subst X: C:\foo\bar
+
+ Treat it like a symlink. This is required to tell an
+ lstat caller that the "drive" is actually pointing
+ somewhere else, thus, it's a symlink in POSIX speak. */
+ if (upath.Length == 14) /* \??\X:\ */
+ {
+ fileattr &= ~FILE_ATTRIBUTE_DIRECTORY;
+ path_flags |= PATH_SYMLINK;
+ }
+ /* For final paths differing in inner path components return
+ length as negative value. This informs path_conv::check
+ to skip realpath handling on the last path component. */
+ else
+ res = -res;
+ break;
+ }
+ }
+ }

/* Normal file. */
file_not_symlink:
--
2.32.0.windows.2

Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
From b671a59da80fa1db6115e3275149f9639681453a Mon Sep 17 00:00:00 2001
From: Jeremy Drake <github@jdrake.com>
Date: Thu, 22 Jul 2021 11:59:16 -0700
Subject: [PATCH 48/N] Cygwin: make option for native inner link handling.

This code has been causing issues with SUBST and mapped network drives,
so add an option (defaulted to on) which can be used to disable it where
needed. MSYS=nonativeinnerlinks
---
winsup/cygwin/environ.cc | 1 +
winsup/cygwin/globals.cc | 1 +
winsup/cygwin/path.cc | 3 ++-
3 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/winsup/cygwin/environ.cc b/winsup/cygwin/environ.cc
index e1dbba3..91e3e9c 100644
--- a/winsup/cygwin/environ.cc
+++ b/winsup/cygwin/environ.cc
@@ -127,6 +127,7 @@ static struct parse_thing
{"disable_pcon", {&disable_pcon}, setbool, NULL, {{false}, {true}}},
{"enable_pcon", {&disable_pcon}, setnegbool, NULL, {{true}, {false}}},
{"winjitdebug", {&winjitdebug}, setbool, NULL, {{false}, {true}}},
+ {"nativeinnerlinks", {&nativeinnerlinks}, setbool, NULL, {{false}, {true}}},
{NULL, {0}, setdword, 0, {{0}, {0}}}
};

diff --git a/winsup/cygwin/globals.cc b/winsup/cygwin/globals.cc
index a729e70..a144a98 100644
--- a/winsup/cygwin/globals.cc
+++ b/winsup/cygwin/globals.cc
@@ -75,6 +75,7 @@ bool wincmdln = true;
winsym_t allow_winsymlinks = WSYM_deepcopy;
bool disable_pcon = true;
bool winjitdebug = false;
+bool nativeinnerlinks = true;

bool NO_COPY in_forkee;

diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc
index 67124bb..2cf8c93 100644
--- a/winsup/cygwin/path.cc
+++ b/winsup/cygwin/path.cc
@@ -3641,7 +3641,8 @@ restart:
goto file_not_symlink;
}
#endif /* __i386__ */
- if ((pc_flags & (PC_SYM_FOLLOW | PC_SYM_NOFOLLOW_REP)) == PC_SYM_FOLLOW)
+ if (nativeinnerlinks
+ && (pc_flags & (PC_SYM_FOLLOW | PC_SYM_NOFOLLOW_REP)) == PC_SYM_FOLLOW)
{
PWCHAR fpbuf = tp.w_get ();
DWORD ret;
--
2.32.0.windows.2

17 changes: 13 additions & 4 deletions msys2-runtime/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
pkgbase=msys2-runtime
pkgname=('msys2-runtime' 'msys2-runtime-devel')
pkgver=3.2.0
pkgrel=14
pkgrel=15
pkgdesc="Cygwin POSIX emulation engine"
arch=('i686' 'x86_64')
url="https://www.cygwin.com/"
Expand Down Expand Up @@ -67,7 +67,10 @@ source=('msys2-runtime'::git://sourceware.org/git/newlib-cygwin.git#tag=cygwin-$
0042-Fix-64-vs-32-bit-type-confusion-in-swprintf.patch
0043-Don-t-fall-back-to-ExitProcess-if-process-handled-Ct.patch
0044-getprocaddr-refactor-cleanup.patch
0045-use-IsWow64Process2-to-detect-arm-cases.patch)
0045-use-IsWow64Process2-to-detect-arm-cases.patch
0046-Revert-Cygwin-Handle-virtual-drives-as-non-symlinks.patch
0047-Cygwin-respect-PC_SYM_FOLLOW-and-PC_SYM_NOFOLLOW_REP.patch
0048-Cygwin-make-option-for-native-inner-link-handling.patch)
sha256sums=('SKIP'
'605f3f31dcca983fad2659f2d8f3531217e3f133757b40b0977e6a17c406c147'
'5d120d24ce55ef08bf459781610e32c4a8e5e0eac73971a60e80590c6432d940'
Expand Down Expand Up @@ -113,7 +116,10 @@ sha256sums=('SKIP'
'04ee4b9ca58bfa8a3c0370d1cecadf50c9c02daf6a4e5ccd4610336155538b71'
'34f9a822fd2cbfd3a556f30ccea6f1dd6bb66b9edf0cd506c0cbb69b6ae437d7'
'54dd5a62e0b9491ed3d1e2ac934297864001c0d6751723342c92a332f105d603'
'526a6466d84e6aa83e0efccded72caaea398f9f2388f6752abaadc011635aa00')
'526a6466d84e6aa83e0efccded72caaea398f9f2388f6752abaadc011635aa00'
'39735120e3e4316e2683a831bea08f292aaf79201fe2a0c67bdf34be284a056d'
'7795780219829aef7388de9e9877fb9fc5d5dc48243ff27354c70af4b993f581'
'93325dc9cf26f1e6e9d41d3487c3a4151d75a8202e3245822bef4e9efe44803e')

# Helper macros to help make tasks easier #
apply_patch_with_msg() {
Expand Down Expand Up @@ -195,7 +201,10 @@ prepare() {
0042-Fix-64-vs-32-bit-type-confusion-in-swprintf.patch \
0043-Don-t-fall-back-to-ExitProcess-if-process-handled-Ct.patch \
0044-getprocaddr-refactor-cleanup.patch \
0045-use-IsWow64Process2-to-detect-arm-cases.patch
0045-use-IsWow64Process2-to-detect-arm-cases.patch \
0046-Revert-Cygwin-Handle-virtual-drives-as-non-symlinks.patch \
0047-Cygwin-respect-PC_SYM_FOLLOW-and-PC_SYM_NOFOLLOW_REP.patch \
0048-Cygwin-make-option-for-native-inner-link-handling.patch
}

build() {
Expand Down

0 comments on commit c88ba5c

Please sign in to comment.