public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
From: Johannes Schindelin <johannes.schindelin@gmx.de>
To: cygwin-patches@cygwin.com
Subject: [PATCH] Fix `Bad address` when running `cmd /c [...]`
Date: Fri, 21 Oct 2022 23:37:35 +0200 (CEST)	[thread overview]
Message-ID: <8rqs6n82-0oq9-2200-944n-74s7o699385o@tzk.qr> (raw)

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

             reply	other threads:[~2022-10-21 21:43 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-21 21:37 Johannes Schindelin [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8rqs6n82-0oq9-2200-944n-74s7o699385o@tzk.qr \
    --to=johannes.schindelin@gmx.de \
    --cc=cygwin-patches@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).