From 99bbaca37fe2a34a8a34995802b5f093f3446770 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 18 Feb 2015 12:32:17 +0000 Subject: [PATCH 01/16] Pass environment variables with empty values There is a difference between an empty value and an unset environment variable. We should not confuse both; If the user wants to unset an environment variable, they can certainly do so (unsetenv(3), or in the shell: 'unset ABC'). This fixes Git's t3301-notes.sh, which overrides environment variables with empty values. Signed-off-by: Johannes Schindelin --- winsup/cygwin/environ.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/winsup/cygwin/environ.cc b/winsup/cygwin/environ.cc index 18c37ee6af..aab079055a 100644 --- a/winsup/cygwin/environ.cc +++ b/winsup/cygwin/environ.cc @@ -1332,11 +1332,11 @@ build_env (const char * const *envp, PWCHAR &envblock, int &envc, Note that this doesn't stop invalid strings without '=' in it etc., but we're opting for speed here for now. Adding complete checking would be pretty expensive. */ - if (len == 1 || !*rest) + if (len == 1) continue; /* See if this entry requires posix->win32 conversion. */ - conv = getwinenv (*srcp, rest, &temp); + conv = !*rest ? NULL : getwinenv (*srcp, rest, &temp); if (conv) { p = conv->native; /* Use win32 path */ @@ -1350,7 +1350,7 @@ build_env (const char * const *envp, PWCHAR &envblock, int &envc, } } #ifdef __MSYS__ - else if (!keep_posix) { + else if (!keep_posix && *rest) { char *win_arg = arg_heuristic_with_exclusions (*srcp, msys2_env_conv_excl_env, msys2_env_conv_excl_count); debug_printf("WIN32_PATH is %s", win_arg); From 450bf389ef6ea46dac8cf70bd0d5247e347306e6 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 20 Feb 2015 13:56:22 +0000 Subject: [PATCH 02/16] 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 920a7ea3c2..4ac10e33b5 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) { r->_errno = EILSEQ; diff --git a/newlib/libc/stdlib/wctomb_r.c b/newlib/libc/stdlib/wctomb_r.c index b4799341e2..d0fe158401 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 f68fcb76f9..89c84bb9a3 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 5be1b92588192dedcf5c281095b9d7aedac3e994 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 20 Feb 2015 11:54:47 +0000 Subject: [PATCH 03/16] 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/how-to-debug-cygwin.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/winsup/cygwin/how-to-debug-cygwin.txt b/winsup/cygwin/how-to-debug-cygwin.txt index 61e91c88d5..953d375864 100644 --- a/winsup/cygwin/how-to-debug-cygwin.txt +++ b/winsup/cygwin/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 a15545a63501bc96d098f90eacdb841ce391eded Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 18 Feb 2015 11:06:15 +0000 Subject: [PATCH 04/16] Add a helpful debug message for posix-to-windows conversion Signed-off-by: Johannes Schindelin --- winsup/cygwin/msys2_path_conv.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/winsup/cygwin/msys2_path_conv.cc b/winsup/cygwin/msys2_path_conv.cc index 54f58fbe8e..41cd6dc4b7 100644 --- a/winsup/cygwin/msys2_path_conv.cc +++ b/winsup/cygwin/msys2_path_conv.cc @@ -238,6 +238,7 @@ void find_end_of_rooted_path(const char** from, const char** to, int* in_string) void sub_convert(const char** from, const char** to, char** dst, const char* dstend, int* in_string) { const char* copy_from = *from; path_type type = find_path_start_and_type(from, false, *to); + debug_printf("found type %d for path %s", type, copy_from); if (type == POSIX_PATH_LIST) { find_end_of_posix_list(to, in_string); From 54cfa3d207842da2040c001a5cc5208aca00278e Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 18 Feb 2015 10:45:01 +0000 Subject: [PATCH 05/16] Stop assuming that there are no spaces in POSIX-style paths Git's test suite most prominently sports a POSIX path with a space in it: the tests are executed in directories whose names have the form 'trash directory.t0123-blub'. Therefore, we *must* handle those names correctly. This fix makes Git's t1504-ceiling-dirs.sh pass. Signed-off-by: Johannes Schindelin --- winsup/cygwin/msys2_path_conv.cc | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/winsup/cygwin/msys2_path_conv.cc b/winsup/cygwin/msys2_path_conv.cc index 41cd6dc4b7..428c58de8a 100644 --- a/winsup/cygwin/msys2_path_conv.cc +++ b/winsup/cygwin/msys2_path_conv.cc @@ -201,7 +201,7 @@ void ppl_convert(const char** from, const char* to, char** dst, const char* dste void find_end_of_posix_list(const char** to, int* in_string) { - for (; **to != '\0' && (in_string ? (**to != *in_string) : **to != ' '); ++*to) { + for (; **to != '\0' && (!in_string || **to != *in_string); ++*to) { } if (**to == *in_string) { @@ -302,12 +302,6 @@ const char* convert(char *dst, size_t dstlen, const char *src) { } continue; } - - if (isspace(*srcit)) { - //sub_convert(&srcbeg, &srcit, &dstit, dstend, &in_string); - //srcbeg = srcit + 1; - break; - } } sub_convert(&srcbeg, &srcit, &dstit, dstend, &in_string); From 15bbbf913a090c1c103b8aae397d2d7abab6e052 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sun, 22 Feb 2015 18:28:02 +0100 Subject: [PATCH 06/16] Avoid unnecessary recursion in find_path_start_and_type() Signed-off-by: Johannes Schindelin --- winsup/cygwin/msys2_path_conv.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/winsup/cygwin/msys2_path_conv.cc b/winsup/cygwin/msys2_path_conv.cc index 428c58de8a..aaecf6ec48 100644 --- a/winsup/cygwin/msys2_path_conv.cc +++ b/winsup/cygwin/msys2_path_conv.cc @@ -341,8 +341,10 @@ path_type find_path_start_and_type(const char** src, int recurse, const char* en if (*it == '\0' || it == end) return NONE; - if (!isalnum(*it) && *it != '/' && *it != '\\' && *it != ':' && *it != '-' && *it != '.') { - return find_path_start_and_type(move(src, 1), true, end); + while (!isalnum(*it) && *it != '/' && *it != '\\' && *it != ':' && *it != '-' && *it != '.') { + recurse = true; + it = ++*src; + if (it == end || *it == '\0') return NONE; } path_type result = NONE; From 4dec9758381e4b5e43a0cdfe0c4bb38f4fb62ef2 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sun, 15 Feb 2015 11:45:48 +0000 Subject: [PATCH 07/16] 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 aaecf6ec48..f1f8475f68 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 580e551c894b45706723abc417ed8a6ecdda763a Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 18 Feb 2015 11:07:17 +0000 Subject: [PATCH 08/16] 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 f1f8475f68..66ed7c9ca4 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 a19c77c5facbcafdbf38e7881d11fa5ce32ed96b Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sun, 22 Feb 2015 18:33:48 +0100 Subject: [PATCH 09/16] 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 66ed7c9ca4..665f951feb 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 dc8f247f8739e9412b3508240b23eb5c8c2d8d84 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 18 Feb 2015 11:07:17 +0000 Subject: [PATCH 10/16] 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 665f951feb..02a69fa3bf 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 19962a86e6a4f30a64dfa221f755f95bac864a87 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 18 Feb 2015 11:07:17 +0000 Subject: [PATCH 11/16] 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 02a69fa3bf..ae24c76210 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 095f9f43e976dcca97ca6fa9080245580f06f6ca Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 18 Feb 2015 11:07:17 +0000 Subject: [PATCH 12/16] 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 ae24c76210..398301aae6 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 59dd4b6d59f9803dbee91dfd1c9cfdd0b4f1b0ed Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 18 Feb 2015 11:07:17 +0000 Subject: [PATCH 13/16] 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 398301aae6..45569d7847 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 a92ecc174da203b67b64a3f1571fe68269abd5dd Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 18 Feb 2015 11:07:17 +0000 Subject: [PATCH 14/16] 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 45569d7847..a5c98819ba 100644 --- a/winsup/cygwin/msys2_path_conv.cc +++ b/winsup/cygwin/msys2_path_conv.cc @@ -455,6 +455,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; @@ -498,11 +500,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 - it) == NULL) { return SIMPLE_WINDOWS_PATH; } + } else if (ch != '.') { + only_dots = 0; + if (ch == '/' || ch == '\\') + has_slashes = 1; } } From 457f2392eaab80255b06202707e7a8075d9e8dfc 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 15/16] 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 a5c98819ba..1953274a98 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 8d3d7ebecbde86e5b5b84241c52eede65a5f2c7d 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 16/16] 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 1953274a98..0fb54f2ea9 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. */