Skip to content

Commit

Permalink
Cygwin: cygwin_GetCommandLineW/A: don't rely on __argv[0] content
Browse files Browse the repository at this point in the history
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: 521953a ("* common.din: Export GetCommandLine{A,W}.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
  • Loading branch information
github-cygwin committed Jan 31, 2024
1 parent 1ce9756 commit bded809
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions winsup/cygwin/kernel32.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit bded809

Please sign in to comment.