4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-02-18 23:12:15 +08:00

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>
This commit is contained in:
Corinna Vinschen 2024-01-31 13:30:05 +01:00
parent 1ce9756ee6
commit bded8091c4

View File

@ -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);
}
}