From bded8091c438d18e1d259864d773891a747c7576 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Wed, 31 Jan 2024 13:30:05 +0100 Subject: [PATCH] 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 --- 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 36951f6a87..f07f80d59d 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); } }