From 3ec60abf5c1fadf102d633ca8149c590bd209f04 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 20 Feb 2015 13:56:22 +0000 Subject: [PATCH 01/12] Handle 8-bit characters under LOCALE=C Even when the character set is specified as ASCII, we should handle data outside the 7-bit range gracefully by simply copying it, even if it is technically no longer ASCII. This fixes several of Git for Windows' tests, e.g. t7400. Signed-off-by: Johannes Schindelin --- newlib/libc/stdlib/mbtowc_r.c | 2 +- newlib/libc/stdlib/wctomb_r.c | 2 +- winsup/cygwin/strfuncs.cc | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/newlib/libc/stdlib/mbtowc_r.c b/newlib/libc/stdlib/mbtowc_r.c index ca876f9a02..ee43736378 100644 --- a/newlib/libc/stdlib/mbtowc_r.c +++ b/newlib/libc/stdlib/mbtowc_r.c @@ -36,7 +36,7 @@ __ascii_mbtowc (struct _reent *r, if (n == 0) return -2; -#ifdef __CYGWIN__ +#ifdef STRICTLY_7BIT_ASCII if ((wchar_t)*t >= 0x80) { _REENT_ERRNO(r) = EILSEQ; diff --git a/newlib/libc/stdlib/wctomb_r.c b/newlib/libc/stdlib/wctomb_r.c index a7f87cd9e2..2c536cec0e 100644 --- a/newlib/libc/stdlib/wctomb_r.c +++ b/newlib/libc/stdlib/wctomb_r.c @@ -29,7 +29,7 @@ __ascii_wctomb (struct _reent *r, if (s == NULL) return 0; -#ifdef __CYGWIN__ +#ifdef STRICTLY_7BIT_ASCII if ((size_t)wchar >= 0x80) #else if ((size_t)wchar >= 0x100) diff --git a/winsup/cygwin/strfuncs.cc b/winsup/cygwin/strfuncs.cc index 0ab2290539..ebd559b66f 100644 --- a/winsup/cygwin/strfuncs.cc +++ b/winsup/cygwin/strfuncs.cc @@ -616,7 +616,11 @@ _sys_mbstowcs (mbtowc_p f_mbtowc, wchar_t *dst, size_t dlen, const char *src, to store them in a symmetric way. */ bytes = 1; if (dst) +#ifdef STRICTLY_7BIT_ASCII *ptr = L'\xf000' | *pmbs; +#else + *ptr = *pmbs; +#endif memset (&ps, 0, sizeof ps); } From e66db6a55eb2225aa65944fc788b4da7e8682085 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 20 Feb 2015 11:54:47 +0000 Subject: [PATCH 02/12] Mention the extremely useful small_printf() function It came in real handy while debugging an issue that strace 'fixed'. Signed-off-by: Johannes Schindelin --- winsup/cygwin/DevDocs/how-to-debug-cygwin.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/winsup/cygwin/DevDocs/how-to-debug-cygwin.txt b/winsup/cygwin/DevDocs/how-to-debug-cygwin.txt index 61e91c88d5..953d375864 100644 --- a/winsup/cygwin/DevDocs/how-to-debug-cygwin.txt +++ b/winsup/cygwin/DevDocs/how-to-debug-cygwin.txt @@ -126,3 +126,9 @@ set CYGWIN_DEBUG=cat.exe:gdb.exe program will crash, probably in small_printf. At that point, a 'bt' command should show you the offending call to strace_printf with the improper format string. + +9. Debug output without strace + + If you cannot use gdb, or if the program behaves differently using strace + for whatever reason, you can still use the small_printf() function to + output debugging messages directly to stderr. From 7209d82ab7d2bc6440f63c1dc1fa0c87c334c9bc Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sun, 15 Feb 2015 11:45:48 +0000 Subject: [PATCH 03/12] Leave arguments starting with a tilde or quote alone It is not a good idea to expand, say, ~/.gitconfig partially: replacing it by ~C:\msys64\.gitconfig is most likely the wrong thing to do! Signed-off-by: Johannes Schindelin --- winsup/cygwin/msys2_path_conv.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/winsup/cygwin/msys2_path_conv.cc b/winsup/cygwin/msys2_path_conv.cc index 5c592919da..95cad7808b 100644 --- a/winsup/cygwin/msys2_path_conv.cc +++ b/winsup/cygwin/msys2_path_conv.cc @@ -341,6 +341,13 @@ path_type find_path_start_and_type(const char** src, int recurse, const char* en if (*it == '\0' || it == end) return NONE; + /* Let's not convert ~/.file to ~C:\msys64\.file */ + if (*it == '~') { +skip_p2w: + *src = end; + return NONE; + } + while (!isalnum(*it) && *it != '/' && *it != '\\' && *it != ':' && *it != '-' && *it != '.') { recurse = true; it = ++*src; From cb6a025a41393a96befc54f2c24dae7c1d2def84 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 18 Feb 2015 11:07:17 +0000 Subject: [PATCH 04/12] Leave Git's :name and :/message arguments alone, please Signed-off-by: Johannes Schindelin --- winsup/cygwin/msys2_path_conv.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/winsup/cygwin/msys2_path_conv.cc b/winsup/cygwin/msys2_path_conv.cc index 95cad7808b..28975b3971 100644 --- a/winsup/cygwin/msys2_path_conv.cc +++ b/winsup/cygwin/msys2_path_conv.cc @@ -348,6 +348,12 @@ path_type find_path_start_and_type(const char** src, int recurse, const char* en return NONE; } + /* + * Prevent Git's :file.txt and :/message syntax from beeing modified. + */ + if (*it == ':') + goto skip_p2w; + while (!isalnum(*it) && *it != '/' && *it != '\\' && *it != ':' && *it != '-' && *it != '.') { recurse = true; it = ++*src; From 8ec99b7c44da39da3f1ab4b0c2f90ce9dda43e97 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sun, 22 Feb 2015 18:33:48 +0100 Subject: [PATCH 05/12] Leave paths containing any special characters alone Signed-off-by: Johannes Schindelin --- winsup/cygwin/msys2_path_conv.cc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/winsup/cygwin/msys2_path_conv.cc b/winsup/cygwin/msys2_path_conv.cc index 28975b3971..d9ec5045cc 100644 --- a/winsup/cygwin/msys2_path_conv.cc +++ b/winsup/cygwin/msys2_path_conv.cc @@ -354,6 +354,20 @@ path_type find_path_start_and_type(const char** src, int recurse, const char* en if (*it == ':') goto skip_p2w; + while (it != end && *it) { + switch (*it) { + case '`': + case '\'': + case '"': + case '*': + case '?': + case '[': + case ']': + goto skip_p2w; + ++it; + } + it = *src; + while (!isalnum(*it) && *it != '/' && *it != '\\' && *it != ':' && *it != '-' && *it != '.') { recurse = true; it = ++*src; From a84de1fa13c7ac7e9686758e255eb84e9e1f3ec9 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 18 Feb 2015 11:07:17 +0000 Subject: [PATCH 06/12] Leave paths containing '/~' alone We do not perform tilde expansion in the MSys2 runtime; let's leave those paths intact for programs that want to expand such paths themselves. Signed-off-by: Johannes Schindelin --- winsup/cygwin/msys2_path_conv.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/winsup/cygwin/msys2_path_conv.cc b/winsup/cygwin/msys2_path_conv.cc index d9ec5045cc..bdde9d447a 100644 --- a/winsup/cygwin/msys2_path_conv.cc +++ b/winsup/cygwin/msys2_path_conv.cc @@ -364,6 +364,10 @@ path_type find_path_start_and_type(const char** src, int recurse, const char* en case '[': case ']': goto skip_p2w; + case '/': + if (it + 1 < end && it[1] == '~') + goto skip_p2w; + break; ++it; } it = *src; From bb0755665d60b0f2ddc8e9ea3793fb1f4b9f2b74 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 18 Feb 2015 11:07:17 +0000 Subject: [PATCH 07/12] Skip posix-to-windows conversion when '::' is seen The substring '::' most likely denotes an IPv6 address, not a path. Signed-off-by: Johannes Schindelin --- winsup/cygwin/msys2_path_conv.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/winsup/cygwin/msys2_path_conv.cc b/winsup/cygwin/msys2_path_conv.cc index bdde9d447a..d6e8930482 100644 --- a/winsup/cygwin/msys2_path_conv.cc +++ b/winsup/cygwin/msys2_path_conv.cc @@ -368,6 +368,11 @@ path_type find_path_start_and_type(const char** src, int recurse, const char* en if (it + 1 < end && it[1] == '~') goto skip_p2w; break; + case ':': + // Avoid mangling IPv6 addresses + if (it + 1 < end && it[1] == ':') + goto skip_p2w; + break; ++it; } it = *src; From 331f11c00f94efca68a7591a2637b26309236186 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 18 Feb 2015 11:07:17 +0000 Subject: [PATCH 08/12] Also leave Git's :./ syntax alone This fixes Git's t1506-rev-parse-diagnosis.sh Signed-off-by: Johannes Schindelin --- winsup/cygwin/msys2_path_conv.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/winsup/cygwin/msys2_path_conv.cc b/winsup/cygwin/msys2_path_conv.cc index d6e8930482..5e55eb1384 100644 --- a/winsup/cygwin/msys2_path_conv.cc +++ b/winsup/cygwin/msys2_path_conv.cc @@ -372,6 +372,14 @@ path_type find_path_start_and_type(const char** src, int recurse, const char* en // Avoid mangling IPv6 addresses if (it + 1 < end && it[1] == ':') goto skip_p2w; + + // Leave Git's :./name syntax alone + if (it + 1 < end && it[1] == '.') { + if (it + 2 < end && it[2] == '/') + goto skip_p2w; + if (it + 3 < end && it[2] == '.' && it[3] == '/') + goto skip_p2w; + } break; ++it; } From 80323e9346c59d3187bb278548ec87093a20d6c1 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 18 Feb 2015 11:07:17 +0000 Subject: [PATCH 09/12] Arguments starting with '@@' are no paths ... so let's skip posix-to-windows conversion on such parameters. This fixes Git's t1508-at-combinations.sh. Signed-off-by: Johannes Schindelin --- winsup/cygwin/msys2_path_conv.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/winsup/cygwin/msys2_path_conv.cc b/winsup/cygwin/msys2_path_conv.cc index 5e55eb1384..c30babf704 100644 --- a/winsup/cygwin/msys2_path_conv.cc +++ b/winsup/cygwin/msys2_path_conv.cc @@ -381,6 +381,11 @@ path_type find_path_start_and_type(const char** src, int recurse, const char* en goto skip_p2w; } break; + case '@': + // Paths do not contain '@@' + if (it + 1 < end && it[1] == '@') + goto skip_p2w; + } ++it; } it = *src; From a91afd46d61aaec1da65d1d5807ae1217554479f Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 18 Feb 2015 11:07:17 +0000 Subject: [PATCH 10/12] Prevent scp-style arguments from being mangled An argument like me@example.com:/tmp/ is not something we should convert into a Windows path; Use the absence of a slash before the colon as a tell-tale that it is *not* a POSIX path list (exception: if the part left of the colon is "." or ".."). Signed-off-by: Johannes Schindelin --- winsup/cygwin/msys2_path_conv.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/winsup/cygwin/msys2_path_conv.cc b/winsup/cygwin/msys2_path_conv.cc index c30babf704..c6f5f71764 100644 --- a/winsup/cygwin/msys2_path_conv.cc +++ b/winsup/cygwin/msys2_path_conv.cc @@ -462,6 +462,8 @@ path_type find_path_start_and_type(const char** src, int recurse, const char* en int starts_with_minus = 0; int starts_with_minus_alpha = 0; + int only_dots = *it == '.'; + int has_slashes = 0; if (*it == '-') { starts_with_minus = 1; it += 1; @@ -505,11 +507,17 @@ path_type find_path_start_and_type(const char** src, int recurse, const char* en if (ch == '/' && *(it2 + 1) == '/') { return URL; } else { + if (!only_dots && !has_slashes) + goto skip_p2w; return POSIX_PATH_LIST; } } else if (memchr(it2, '=', end - it2) == NULL) { return SIMPLE_WINDOWS_PATH; } + } else if (ch != '.') { + only_dots = 0; + if (ch == '/' || ch == '\\') + has_slashes = 1; } } From 5246c137d6f30077aab548cb7459cffe0325b2f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=A7=88=EB=88=84=EC=97=98?= Date: Mon, 9 Mar 2015 16:24:43 +0100 Subject: [PATCH 11/12] Fixed path converting with non ascii char. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a non ascii char is at the beginning of a path the current conversion destroys the path. This fix will prevent this with an extra check for non-ascii UTF-8 characters. Helped-by: Johannes Schindelin Signed-off-by: 마누엘 --- winsup/cygwin/msys2_path_conv.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/winsup/cygwin/msys2_path_conv.cc b/winsup/cygwin/msys2_path_conv.cc index c6f5f71764..7dbef1a44b 100644 --- a/winsup/cygwin/msys2_path_conv.cc +++ b/winsup/cygwin/msys2_path_conv.cc @@ -390,7 +390,7 @@ path_type find_path_start_and_type(const char** src, int recurse, const char* en } it = *src; - while (!isalnum(*it) && *it != '/' && *it != '\\' && *it != ':' && *it != '-' && *it != '.') { + while (!isalnum(*it) && !(0x80 & *it) && *it != '/' && *it != '\\' && *it != ':' && *it != '-' && *it != '.') { recurse = true; it = ++*src; if (it == end || *it == '\0') return NONE; From 78a29ea91ea36a528fdee5d126b114682f5dca3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=A7=88=EB=88=84=EC=97=98?= Date: Wed, 17 Jun 2015 09:30:41 +0200 Subject: [PATCH 12/12] path-conversion: Introduce ability to switch off conversion. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When calling windows native apps from MSYS2, the runtime tries to convert commandline arguments by a specific set of rules. See [MinGW wiki] (http://www.mingw.org/wiki/Posix_path_conversion). If the user does not want that behavior on a big scale, e.g. inside a bash script, the user can now set the the environment variable `MSYS_NO_PATHCONV` when calling native windows commands. Signed-off-by: 마누엘 --- winsup/cygwin/msys2_path_conv.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/winsup/cygwin/msys2_path_conv.cc b/winsup/cygwin/msys2_path_conv.cc index 7dbef1a44b..133939a7a8 100644 --- a/winsup/cygwin/msys2_path_conv.cc +++ b/winsup/cygwin/msys2_path_conv.cc @@ -348,6 +348,14 @@ path_type find_path_start_and_type(const char** src, int recurse, const char* en return NONE; } + /* + * Skip path mangling when environment indicates it. + */ + const char *no_pathconv = getenv ("MSYS_NO_PATHCONV"); + + if (no_pathconv) + goto skip_p2w; + /* * Prevent Git's :file.txt and :/message syntax from beeing modified. */