Merge pull request #3248 from dscho/fix-bad-address-in-cmd-invocation-in-msys2-runtime

msys2-runtime: fix `Bad address` when running `cmd /c <command>`
This commit is contained in:
Christoph Reiter
2022-10-24 09:27:58 +02:00
committed by GitHub
42 changed files with 96 additions and 163 deletions

View File

@@ -2708,6 +2708,3 @@ index eb2a870..3bf9d9f 100755
lt_cv_dlopen="dlopen"
lt_cv_dlopen_libs=
;;
--
2.37.3

View File

@@ -24,6 +24,3 @@ index b900960..617a9c2 100755
} else {
my ($file, $member, $symbol) = m%^([^:]*):([^:]*(?=:))?.* T (.*)%o;
next if !defined($symbol) || $symbol =~ $exclude_regex;
--
2.37.3

View File

@@ -1441,6 +1441,3 @@ index 4c98eef..ad35d23 100644
"\n"
"The \"-b\" means 'skip the help pages'. You can omit this until you're\n"
"familiar with the report layout. The gprof documentation explains\n"
--
2.37.3

View File

@@ -1093,6 +1093,3 @@ index e3a65f8..1aeec8d 100644
void dup_all ()
{
for (int i = calloced; i < argc; i++)
--
2.37.3

View File

@@ -190,6 +190,3 @@ index 3502166..daed73f 100644
/* Add a hint to the sysname, that we're running under WOW64. This might
give an early clue if somebody encounters problems. */
--
2.37.3

View File

@@ -396,6 +396,3 @@ index 6aae33c..5736ffb 100644
if (gecos)
free (gecos);
if (home)
--
2.37.3

View File

@@ -232,6 +232,3 @@ index a430d98..17646a8 100644
/* Default technique creating a symlink. */
buf = tp.t_get ();
cp = stpcpy (buf, SYMLINK_COOKIE);
--
2.37.3

View File

@@ -34,6 +34,3 @@ index 296c890..2e290a8 100644
#ifdef __MSYS__
else if (*newp == 'M' && strncmp (newp, "MSYS=", 5) == 0)
parse_options (newp + 5);
--
2.37.3

View File

@@ -28,6 +28,3 @@ index 283041a..49cd941 100644
if (!moreinfo->envp || !envblock)
{
set_errno (E2BIG);
--
2.37.3

View File

@@ -53,6 +53,3 @@ index 17646a8..77480aa 100644
}
}
--
2.37.3

View File

@@ -75,6 +75,3 @@ index ee75d3b..d652b32 100644
NOTSTATE (myself, PID_CYGPARENT) && allow_glob);
/* Convert argv[0] to posix rules if it's currently blatantly
--
2.37.3

View File

@@ -55,6 +55,3 @@ index d652b32..f75ba5f 100644
*p++ = '\\';
size_t cnt = isascii (*s) ? 1 : mbtowc (NULL, s, MB_CUR_MAX);
if (cnt <= 1 || cnt == (size_t)-1)
--
2.37.3

View File

@@ -67,6 +67,3 @@ index de4abc4..3dbce3b 100644
ret = CreateProcess (0, one_line.buf, /* command line */
NULL, /* Security */
NULL, /* thread */
--
2.37.3

View File

@@ -20,6 +20,3 @@ index f75ba5f..4dc8be8 100644
/* Scan command line until there is nothing left. */
while (*cmd)
{
--
2.37.3

View File

@@ -19,6 +19,3 @@ index 3dbce3b..4e5d24c 100644
SetConsoleCtrlHandler (NULL, 0);
/* Commit message for this code was:
--
2.37.3

View File

@@ -171,6 +171,3 @@ index 49cd941..8359f12 100644
}
/* Check if we have been called from exec{lv}p or spawn{lv}p and mask
--
2.37.3

View File

@@ -20,6 +20,3 @@ index 8359f12..4f28335 100644
(opt & FE_DLL) ? stat_suffixes : exe_suffixes);
if (buf.isdir ())
--
2.37.3

View File

@@ -21,6 +21,3 @@ index e254397..2a03ac1 100644
LoadDLLfunc (QueryUnbiasedInterruptTimePrecise, 4, KernelBase)
LoadDLLfunc (VirtualAlloc2, 28, KernelBase)
--
2.37.3

View File

@@ -35,6 +35,3 @@ index 4e5d24c..a4713a2 100644
SetConsoleCtrlHandler (NULL, 0);
/* Commit message for this code was:
--
2.37.3

View File

@@ -49,6 +49,3 @@ index 1b8d8e2..29ca896 100644
bool NO_COPY in_forkee;
--
2.37.3

View File

@@ -52,6 +52,3 @@ index 49631d6..daaa1ec 100644
case setbit:
*k->setting.x &= ~k->values[istrue].i;
if (istrue || (eq && strtol (eq, NULL, 0)))
--
2.37.3

View File

@@ -29,6 +29,3 @@ index 0890390..f6ffb1c 100644
__std[0], __std[1]);
/* Reinstate the close-on-exec state */
--
2.37.3

View File

@@ -50,6 +50,3 @@ index 0000000..4e1d498
+ with:
+ name: install
+ path: _dest/
--
2.37.3

View File

@@ -41,6 +41,3 @@ index 0000000..57bd30e
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ run: |
+ git push https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$GITHUB_REPOSITORY refs/heads/cygwin/master 'refs/tags/*:refs/tags/*'
--
2.37.3

View File

@@ -51,6 +51,3 @@ index 649084d..28056e6 100644
</listitem>
<listitem>
--
2.37.3

View File

@@ -30,6 +30,3 @@ index f9a9a7a..4b541a8 100644
jobs:
fedora-build:
--
2.37.3

View File

@@ -63,6 +63,3 @@ index 4f28335..bc9dc5a 100644
c_flags |= CREATE_DEFAULT_ERROR_MODE;
/* We're adding the CREATE_BREAKAWAY_FROM_JOB flag here to workaround
--
2.37.3

View File

@@ -380,6 +380,3 @@ index 0000000..25814c7
+
+ return 0;
+}
--
2.37.3

View File

@@ -504,6 +504,3 @@ index 0000000..0486a0c
+}
+
+#endif
--
2.37.3

View File

@@ -49,6 +49,3 @@ index d0fb547..ad718c3 100644
CloseHandle (h);
}
--
2.37.3

View File

@@ -50,6 +50,3 @@ index 9edd949..9a3ad7a 100644
{
PWCHAR fpbuf = tp.w_get ();
DWORD ret;
--
2.37.3

View File

@@ -44,6 +44,3 @@ index 534d674..d448ede 100644
uninstall-extra-man:
for i in *.1 ; do \
--
2.37.3

View File

@@ -26,6 +26,3 @@ index 23a3c23..f1fe01d 100644
@$(MKDIR_P) $(DESTDIR)$(bindir)
$(INSTALL_PROGRAM) $(TEST_DLL_NAME) $(DESTDIR)$(bindir)/$(DLL_NAME)
@$(MKDIR_P) $(DESTDIR)$(toollibdir)
--
2.37.3

View File

@@ -106,6 +106,3 @@ index 71c3f22..f33740d 100644
void __reg3 add_cache (const char *in_posix, const char *in_native = NULL);
const char * get_native () const {return native ? native + namelen : NULL;}
const char * get_posix () const {return posix ? posix : NULL;}
--
2.37.3

View File

@@ -46,6 +46,3 @@ index 5c197a6..5afac8d 100644
/* 80 */
/* P Q R S T U V W */
WC, 0, 0, WC, WC, 0, 0, 0,
--
2.37.3

View File

@@ -80,6 +80,3 @@ index daed73f..f6a5f88 100644
/* Add a hint to the sysname, that we're running under WOW64. This might
give an early clue if somebody encounters problems. */
--
2.37.3

View File

@@ -23,6 +23,3 @@ index 6c15138..6a65dd6 100644
bool winjitdebug = false;
bool nativeinnerlinks = true;
--
2.37.3

View File

@@ -43,6 +43,3 @@ index 5afac8d..522d7d5 100644
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);
--
2.37.3

View File

@@ -55,6 +55,3 @@ index 522d7d5..128f34d 100644
continue;
/* See if this entry requires posix->win32 conversion. */
--
2.37.3

View File

@@ -32,6 +32,3 @@ index 128f34d..b431d3c 100644
{
/* Don't pass timezone environment to non-msys applications */
if (ascii_strncasematch(*srcp, "TZ=", 3))
--
2.37.3

View File

@@ -0,0 +1,50 @@
From f975120d20d51ca11217e4abbf16cc51ab8c9290 Mon Sep 17 00:00:00 2001
From: Takashi Yano <takashi.yano@nifty.ne.jp>
Date: Sat, 22 Oct 2022 14:05:40 +0900
Subject: [PATCH 41/N] Cygwin: pty: Fix 'Bad address' error when running
'cmd.exe /c dir'
- If the command executed is 'cmd.exe /c [...]', runpath in spawn.cc
will be NULL. In this case, is_console_app(runpath) check causes
access violation. This case also the command executed is obviously
console app., therefore, treat it as console app to fix this issue.
Addresses: https://github.com/msys2/msys2-runtime/issues/108
This is a backport of 08281cf4cc (Cygwin: pty: Fix 'Bad address' error
when running 'cmd.exe /c dir', 2022-10-22).
The original patch that was replaced by this commit had this additional
information that is now sadly lost in Cygwin's history:
In 2b4f986e49 (Cygwin: pty: Treat *.bat and *.cmd as a non-cygwin
console app., 2022-07-31), we introduced a bug fix that specifically
looks for a suffix of the command's file name.
However, that file name might be set to `NULL`, namely when
`null_app_name == true`, which is the case when we detected a
command-line `cmd /c [...]`.
But the commit mentioned above did not account for that possibility,
instead assuming that it always has to check the file name for a `.bat`
or `.cmd` suffix. As a consequence, `cmd /c [...]` invocations are
completely broken in v3.3.6, resulting in a `Bad address` error.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
winsup/cygwin/spawn.cc | 2 ++
1 file changed, 2 insertions(+)
diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc
index bc9dc5a..9636109 100644
--- a/winsup/cygwin/spawn.cc
+++ b/winsup/cygwin/spawn.cc
@@ -198,6 +198,8 @@ handle (int fd, bool writing)
static bool
is_console_app (WCHAR *filename)
{
+ if (filename == NULL)
+ return true; /* The command executed is command.com or cmd.exe. */
HANDLE h;
const int id_offset = 92;
h = CreateFileW (filename, GENERIC_READ, FILE_SHARE_READ,

View File

@@ -4,7 +4,7 @@
pkgbase=msys2-runtime
pkgname=('msys2-runtime' 'msys2-runtime-devel')
pkgver=3.3.6
pkgrel=2
pkgrel=3
pkgdesc="Cygwin POSIX emulation engine"
arch=('i686' 'x86_64')
url="https://www.cygwin.com/"
@@ -64,48 +64,50 @@ source=('msys2-runtime'::git://sourceware.org/git/newlib-cygwin.git#tag=cygwin-$
0037-fixup-Revert-Default-to-disable_pcon.patch
0038-Pass-environment-variables-with-empty-values.patch
0039-Optionally-disallow-empty-environment-values-again.patch
0040-build_env-respect-the-MSYS-environment-variable.patch)
0040-build_env-respect-the-MSYS-environment-variable.patch
0041-Cygwin-pty-Fix-Bad-address-error-when-running-cmd.ex.patch)
sha256sums=('SKIP'
'8e26c673b763366a085eada2250bfcaf182d1f357eb23a62c57a20fe8a0346f3'
'c4cc134ab6fa1c17b5ee428c8604861f1a4580ac14aef25740da8597de84800e'
'f30d275031db52430c7ddef7ed1e54eb8d934251b11c812725d32d1ba380a3e9'
'09effb95abc166cde9c3a3d7f9aa1bd53c1161c3706c6c5e85c29802dfe7fe63'
'7208bf2dffe1c27f9a8ff63e24ee3b4f9e7448aef8a5bd6f014b50b63bb49bae'
'c0c833ee0f038fcb29d56a49df62278d0e489ca85e6e4ca8b7ae6600c7bc69a3'
'99e2e82848a9c4e56f75bec6d016f8d38869373f9c809029ed2179eef5efe033'
'bd6174a58ebe88c29421f23ccfaee157e4fa18a4b497e2d391875b2507875a63'
'2d36efb8c2355c8d6eb4652cea2abcf7b5cec1e8931dc33d90dc7ee0ca69e1df'
'92e8553378e380b8db643d7ca3604b84b13a0dba38263d6aca33169bcf62214c'
'a6cd762892edd38bf8c62b513fe3be1c8bdcfdabe5596814185dbf37c40cdec3'
'1b0bd86c9d9d489d00396ab259f0a5fd6489aef24c47ba51c1ba85b0d23e0765'
'337674665b7bfd58a80766d5d7d91390796ac2f4426db9cc071e00e3914e29d5'
'779949b0f9143b68733ec7fe0f01f2eaea8e589df5fd1dd2fe4fc9046ff73b18'
'15236a2889c68d6f97dde91059fb725c855c3085f89ca8735d82a5727c8e05c1'
'1bf0f0f554c57e3d75fd936eb6e1a0dbffe192e91164ffe16ba0e95da6298326'
'd0d704e9c8163c8bd731aab8785396d64262a16580e219426052895f63929187'
'35948eb27c4eec64f986eea4689963af547dba4c8722d2c97607a2164a9bb78c'
'324e313839c4d78e1a2bb8e37eee143f9ba3bf8f8e6c97c09f20fc945503734b'
'ddcb985482a8409227252e95e790ce3de3c256d18af29fa8bb3e1887fbeee585'
'535dbc7eae11e9cc5307b7023e967824ce187ab981e31663af289107cfc9757e'
'a35032b628032deadad31fde7c7dd04c3a28f15095fb10a31f26e0f489f35d69'
'3f43a8ae895f0100399b198ad66897ae59d74da7c2e8ceba0fc6d82582d4ba34'
'5680983a9ac7943800aec6b1504cd0c7300d9590d3e0321a9fd2091005595aa7'
'd33334697d2b345e9cd54e8a879aef497d5f699ed194072123fed7268a7155a7'
'a0b5a0d39b7585885b52d8df3522ab7bf9a4b831f7e64a4ce4842135b363124b'
'52e924fe006400dbe2def51ac04a09173a6e0fabaa6417b43f5114bc35e28ca1'
'fc0605ba52e4091081063a98f7757110d2f353027d2e146960531299d2c3b3bc'
'3dc45ac3b3bf2b32bb7e17639e3dd8ed599bad636c9883aa0fa77dfa79471432'
'4c340f2b767833a11b0b57d33780f6150bba231946f2cece334dbb46475499a6'
'835ac7031ff00e4a70bb2b7e5a4e4c75dc8c449b4d8095fc59dada42068fb380'
'd19dee1e9255789387a4d79d1f6f469adb8d0cb3424c6469049c917df589b0a6'
'4631a6186534f7b9abbd5685f858cffc40634df540cb7db5f3102bf7e6f6dfc6'
'ba34f8b5bc39e273a5e594ba3f893367359fb72ed5fe8f9ed80d03a7702041c9'
'8ebe2924fd3bfcc5fe51e731ddb29b800f0f49c7776ce2af084300888cb966c2'
'90f482551aa593215c0eb574863f5d6f492b0cca63469a8c80eaae72b82dee74'
'f4641a5c4c9571362ef7dc855d3340cb9bf7fe512a2042e92e6b8e3f93a5293f'
'57d4380abbd5536dacb9efea24749756af31c6926473f78a62681d65b431b3a9'
'c4d5ad6a5960b735ddd900445dc2c3428c1d1cea1454150a8b8b77ff09c42dc9'
'd12ae4e081ef49e5f00579baf45d9c3e245ed1c3542ea988f81ac38b5f00c71d')
'c375315e58181ee5589b7966101aa095de3f864a579c3c3f0f0683595d4e428d'
'01ea2b131cf5a3b27fdbc458019eac14e45a36782ce3ce33e62328eefcd2d02e'
'475ddea4d86605ab097f98ec764951a9d647ea3100dea0e1620f57044ea4a114'
'6775247d7a213268bbb2315f764ebc9faf9967b70a95dbc6e9de53fe04142433'
'91e2a72a980aeefadc215cd36147c56666679bbcd68c60120278b6270454b710'
'54cd198f3ce3931884220c8938bd0f348e0889c20b36d110ded9302ec7364c34'
'31a4bcb985e03c45f16644a1604ebc649dc50586968050f8819035b84f80bcf3'
'e9cfe4d79ac294e19e648f51a8bb491231204d8eb9c6a2e998a7cc2506ca47ea'
'816e98ee5ad15d3cfb75598e2e20e11272ac6867a7bd9b0a3fea0ac0ba4daf69'
'e895d76936f4668bb7b67581ef642e845968dfb86e21d654dde98727f0ebabb2'
'f416f109d323618ff3d7240ea7845d5ab3221a8a6c6074e36a34e62fbaabdbfd'
'e710a9eed8bd767d97acb2d2cdc56eef880e02b20f1b14fdf462678954e3a896'
'ce72bc18fcf101d14c0623c1d459b141ba883934939c70d198d69932ec4873c7'
'5f5850cd725c4df6ce6cc86d07da1ed696e119d8bb80602380c4941aa10d0784'
'8df334362506dbe9de56017c0df1d3459b5c6e29860b73a5e9ebd0421b2f3a6a'
'988a2d365302c73ab482bd1f0d4edea8e687de7fdf068e5bec3aafaf33d63a58'
'f9aa893686405b8b92b3d585b7a7dff35f9345a64a282f75d8962e92f86bea25'
'b3073a6b2acf836f5b3286ff8be66633ed4f93280d50186635a3fcfb4cdc3745'
'52cd166461fc2cc3c880c174160516a93d456dad44f382aed518aa9bfa36303f'
'cee973f136152e6a5cd987bba85937584c9459aff1c2777134a99526b2d5512d'
'221dacc354d4f27443665bfe32b114235ef7305c55c9189c77f636c46522ee80'
'bd985989895e51688072d7751976ecb83720c8e0786126d7025ba355b64f6edc'
'0f9e96fab22bb5ea0d4d6dc4a943ab56f28c0dab675e57a75b892c491d51808b'
'61a9684bde1165f4afbf1ace3ddb873e6c8cc92e65930aff0c45e20b4d12a86a'
'a02f701e524e0508149e3f16296db4f76382482ff114b170a1cc136d3ad65b2d'
'205a6b56ab3bfa9209c3c1f89aac1491a75b6700e7656252f9afd84800bb3bc1'
'8f817df7130fdec6477a69ba77394183c0dd7d8c2edb133b680f3be542e2896f'
'5e7661cb53a050bc5470ea2d749d5e7524b02ae89dc929d17a9272508ddc6d4c'
'13bbe25b3b60791b327163109e697ba160a70f58d13684aa52ab9bac00d5a555'
'0b2c75b5f7e04c479d0a5ec7170e430e641b5449aa24232b5c3f073767a8fdbc'
'53e11ea902756768f8601fa243ed6602b54c30df514a652c0d8e15de245a46c3'
'1f03ce6418812425494695290711b7076c8678aeca36b2683ef0ec1875d1e0c3'
'25c1e568b9f03772ca7a1bce1c90b6a9e22d49e15b7b372a0921dcd0e66c98d2'
'bf0ff70c2ee6a4b9db7ed52154f5ba02d4a1d92cbfc2618ac86723c49156034f'
'658ee069e968c7def37300bb7058bb17cd6e079eb789fe86b3af0fe1ae86a4cb'
'59836bc012a3cf8dd245615f4cbeb4c3cb141434a30226c5e9647f265b589faf'
'de0e56d2f01f02f1d4014cade92b4c78a90fb85f2409846a932b57b3c6d0b213'
'30a3f2c7fba69aa9942f18f98c4289a8d89d6a6187f84a57895dbaa65f54d30e'
'fcf8caa3cab42f0ea228b8e3213238ce2354f13dea27289c6899b0a209ffd204'
'0e5ba38fa125822330b1842d487aee78126bf7ea503eb1fe970440cf1504f25f'
'd5f6913d0d1439973a3687b3ef8948b6859ec302c0f810e9343c7e44f9146176')
# Helper macros to help make tasks easier #
apply_patch_with_msg() {
@@ -182,7 +184,8 @@ prepare() {
0037-fixup-Revert-Default-to-disable_pcon.patch \
0038-Pass-environment-variables-with-empty-values.patch \
0039-Optionally-disallow-empty-environment-values-again.patch \
0040-build_env-respect-the-MSYS-environment-variable.patch
0040-build_env-respect-the-MSYS-environment-variable.patch \
0041-Cygwin-pty-Fix-Bad-address-error-when-running-cmd.ex.patch
}
build() {