public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
* [PATCH] Fix `Bad address` when running `cmd /c [...]`
@ 2022-10-21 21:37 Johannes Schindelin
  2022-10-22  1:36 ` Takashi Yano
  0 siblings, 1 reply; 7+ messages in thread
From: Johannes Schindelin @ 2022-10-21 21:37 UTC (permalink / raw)
  To: cygwin-patches

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.

Let's guard the code properly so that it does not try to look at the
file name suffix of `(WCHAR *)NULL`.

This fixes https://github.com/msys2/msys2-runtime/issues/108

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
Published-As: https://github.com/dscho/msys2-runtime/releases/tag/fix-bad-address-in-cmd-invocation-v1
Fetch-It-Via: git fetch https://github.com/dscho/msys2-runtime fix-bad-address-in-cmd-invocation-v1

 winsup/cygwin/spawn.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc
index d9d7716519..d4e7f10e2b 100644
--- a/winsup/cygwin/spawn.cc
+++ b/winsup/cygwin/spawn.cc
@@ -209,7 +209,7 @@ is_console_app (WCHAR *filename)
   char *p = (char *) memmem (buf, n, "PE\0\0", 4);
   if (p && p + id_offset < buf + n)
     return p[id_offset] == '\003'; /* 02: GUI, 03: console */
-  else
+  else if (filename)
     {
       wchar_t *e = wcsrchr (filename, L'.');
       if (e && (wcscasecmp (e, L".bat") == 0 || wcscasecmp (e, L".cmd") == 0))

base-commit: 1ca46b22d6edb3d469b51475e8b096d86deaac67
--
2.38.1.windows.1

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-10-23 20:48 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-21 21:37 [PATCH] Fix `Bad address` when running `cmd /c [...]` Johannes Schindelin
2022-10-22  1:36 ` Takashi Yano
2022-10-22  1:54   ` Takashi Yano
2022-10-22  5:37     ` Takashi Yano
2022-10-22  5:55       ` Johannes Schindelin
2022-10-22  6:07         ` Takashi Yano
2022-10-23 20:48           ` Johannes Schindelin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).