[PATCH v2 0/1] MR10696: shcore: 0 terminate params->WindowTitle when turning into WCHAR
WindowTitle is not necessarily NUL terminated. Reported-By: Dirk Mueller <dmueller@suse.de> Found-by: Gemini 3.1 Pro Signed-off-by: Marcus Meissner <marcus@jet.franken.de> -- v2: shcore: 0 terminate params->WindowTitle when turning into WCHAR https://gitlab.winehq.org/wine/wine/-/merge_requests/10696
From: Marcus Meissner <marcus@jet.franken.de> WindowTitle is not necessarily NUL terminated. Reported-By: Dirk Mueller <dmueller@suse.de> Found-by: Gemini 3.1 Pro Signed-off-by: Marcus Meissner <marcus@jet.franken.de> --- dlls/shcore/main.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dlls/shcore/main.c b/dlls/shcore/main.c index ea911288c6e..90911ea0a10 100644 --- a/dlls/shcore/main.c +++ b/dlls/shcore/main.c @@ -293,8 +293,11 @@ HRESULT WINAPI GetCurrentProcessExplicitAppUserModelID(WCHAR **appid) params = RtlGetCurrentPeb()->ProcessParameters; if (params->dwFlags & STARTF_TITLEISAPPID) { - *appid = CoTaskMemAlloc( params->WindowTitle.MaximumLength ); - if (*appid) wcscpy( *appid, params->WindowTitle.Buffer ); + *appid = CoTaskMemAlloc( params->WindowTitle.MaximumLength + sizeof(WCHAR)); + if (*appid) { + memcpy( *appid, params->WindowTitle.Buffer, params->WindowTitle.MaximumLength ); + *appid[params->WindowTitle.MaximumLength/sizeof(WHCAR)] = 0; + } else ret = E_OUTOFMEMORY; } else ret = E_FAIL; -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10696
Actually it's guaranteed to be null-terminated, as demonstrated by the fact that GetStartupInfoW directly returns the buffer as string pointer. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/10696#note_137055
Vishnunithyasoundhar S (@svishnunithyasoundhar) commented about dlls/shcore/main.c:
params = RtlGetCurrentPeb()->ProcessParameters; if (params->dwFlags & STARTF_TITLEISAPPID) { - *appid = CoTaskMemAlloc( params->WindowTitle.MaximumLength ); - if (*appid) wcscpy( *appid, params->WindowTitle.Buffer ); + *appid = CoTaskMemAlloc( params->WindowTitle.MaximumLength + sizeof(WCHAR)); + if (*appid) { + memcpy( *appid, params->WindowTitle.Buffer, params->WindowTitle.MaximumLength ); + *appid[params->WindowTitle.MaximumLength/sizeof(WHCAR)] = 0;
```suggestion:-0+0 *appid[params->WindowTitle.MaximumLength/sizeof(WCHAR)] = 0; ``` -- https://gitlab.winehq.org/wine/wine/-/merge_requests/10696#note_137057
On Sun Apr 19 11:55:03 2026 +0000, Vishnunithyasoundhar S wrote:
```suggestion:-0+0 *appid[params->WindowTitle.MaximumLength/sizeof(WCHAR)] = 0; ```
Resolving this comment as its unnecessary. I just read the previous comment. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/10696#note_137058
participants (4)
-
Alexandre Julliard (@julliard) -
Marcus Meissner -
Marcus Meissner (@msmeissn) -
Vishnunithyasoundhar S (@svishnunithyasoundhar)