public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org>
To: cygwin-cvs@sourceware.org
Subject: [newlib-cygwin/main] Cygwin: cygwin_GetCommandLineW/A: don't rely on __argv[0] content
Date: Thu,  1 Feb 2024 11:39:55 +0000 (GMT)	[thread overview]
Message-ID: <20240201113955.E54B43858015@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=bded8091c438d18e1d259864d773891a747c7576

commit bded8091c438d18e1d259864d773891a747c7576
Author:     Corinna Vinschen <corinna@vinschen.de>
AuthorDate: Wed Jan 31 13:30:05 2024 +0100
Commit:     Corinna Vinschen <corinna@vinschen.de>
CommitDate: Wed Jan 31 20:11:58 2024 +0100

    Cygwin: cygwin_GetCommandLineW/A: don't rely on __argv[0] content
    
    Since it's possible to change the __argv array, we should not rely
    on __argv[0] actually representing the windows executable path in
    any way.  Use the real path stored in global_progname instead.
    
    Fixes: 521953a83a885 ("* common.din: Export GetCommandLine{A,W}.")
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/cygwin/kernel32.cc | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/winsup/cygwin/kernel32.cc b/winsup/cygwin/kernel32.cc
index 36951f6a87be..f07f80d59ddc 100644
--- a/winsup/cygwin/kernel32.cc
+++ b/winsup/cygwin/kernel32.cc
@@ -419,14 +419,17 @@ static UNICODE_STRING *
 ucmd ()
 {
   static UNICODE_STRING wcmd;
+  tmp_pathbuf tp;
+
   if (!wcmd.Buffer)
     {
       linebuf cmd;
-      path_conv real_path (__argv[0]);
+      char *win_progname = tp.c_get ();
+      sys_wcstombs (win_progname, NT_MAX_PATH, global_progname);
       av newargv (__argc, __argv);
       if (newargv.argc)
 	{
-	  cmd.fromargv (newargv, real_path.get_win32 (), true);
+	  cmd.fromargv (newargv, win_progname, true);
 	  RtlInitUnicodeString (&wcmd, cmd);
 	}
     }

                 reply	other threads:[~2024-02-01 11:39 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20240201113955.E54B43858015@sourceware.org \
    --to=corinna@sourceware.org \
    --cc=cygwin-cvs@sourceware.org \
    /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).