[PATCH v2 0/1] MR9882: kernelbase: Trim whitespaces from the quoted 'cmdline'
If 'name' does not have a suffix, a suffix will be appended in find_exe_file. If 'name' contains spaces, it will result in an incorrect filename being concatenated. In the log of a certain installer, I saw an entry like this: trace:process:CreateProcessInternalW app (null) cmdline L"\"C:\\Program Files\\some folder\\7za \" x -y -aos \"-oC://Program Files//target folder/\" \"C://Program Files//source.zip\"" Signed-off-by: YeshunYe <yeyeshun@uniontech.com> -- v2: kernelbase: Trim whitespaces from the quoted 'cmdline' https://gitlab.winehq.org/wine/wine/-/merge_requests/9882
From: YeshunYe <yeyeshun@uniontech.com> If 'name' does not have a suffix, a suffix will be appended in find_exe_file. If 'name' contains spaces, it will result in an incorrect filename being concatenated. Signed-off-by: YeshunYe <yeyeshun@uniontech.com> --- dlls/kernelbase/process.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/dlls/kernelbase/process.c b/dlls/kernelbase/process.c index 3656e40280d..d3a5b91074f 100644 --- a/dlls/kernelbase/process.c +++ b/dlls/kernelbase/process.c @@ -87,10 +87,16 @@ static WCHAR *get_file_name( WCHAR *cmdline, WCHAR *buffer, DWORD buflen ) if (cmdline[0] == '"' && (p = wcschr( cmdline + 1, '"' ))) { - int len = p - cmdline - 1; + int len; + /* trim spaces in quotes */ + const WCHAR* start = cmdline + 1; + const WCHAR* end = p - 1; + while (*start == ' ') start++; + while (*end == ' ') end--; + len = end - start + 1; /* extract the quoted portion as file name */ if (!(name = RtlAllocateHeap( GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR) ))) return NULL; - memcpy( name, cmdline + 1, len * sizeof(WCHAR) ); + memcpy( name, start, len * sizeof(WCHAR) ); name[len] = 0; if (!find_exe_file( name, buffer, buflen )) goto done; -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/9882
On Wed Jan 14 08:31:55 2026 +0000, Yeshun Ye wrote:
I apologize for the oversight, the "//" comments are meant to be deleted. Regarding the test cases, do I need to test the "CreateProcessInternalW" function? As for "get_file_name" and "find_exe_file", they are static and cannot be accessed in the test cases. I have already fixed the comment issues. Regarding the test cases, I need to wait for your response to know which function's test cases should be added.
-- https://gitlab.winehq.org/wine/wine/-/merge_requests/9882#note_126907
On Wed Jan 14 08:45:14 2026 +0000, Yeshun Ye wrote:
I have already fixed the comment issues. Regarding the test cases, I need to wait for your response to know which function's test cases should be added. CreateProcessW should do (in dlls/kernel32/tests/process.c)
-- https://gitlab.winehq.org/wine/wine/-/merge_requests/9882#note_126913
participants (3)
-
eric pouech (@epo) -
Yeshun Ye (@yeyeshun) -
YeshunYe