[PATCH v2 0/2] MR10933: kernelbase: Add null check for str in OutputDebugStringW
The following code crashes wine but seems to be OK in Windows: ``` #include <windows.h> int main() { OutputDebugStringW(NULL); return 0; } ``` The MR aligns behavior of `OutputDebugStringW` to Windows by adding a null check and bailing out of `OutputDebugStringW`. -- v2: kernel32/tests: Add null pointer test for OutputDebugStringW https://gitlab.winehq.org/wine/wine/-/merge_requests/10933
From: Matthias Gorzellik <matthias.gorzellik@gmail.com> --- dlls/kernelbase/debug.c | 1 + 1 file changed, 1 insertion(+) diff --git a/dlls/kernelbase/debug.c b/dlls/kernelbase/debug.c index a600b6b59c9..8656859b7bb 100644 --- a/dlls/kernelbase/debug.c +++ b/dlls/kernelbase/debug.c @@ -281,6 +281,7 @@ void WINAPI DECLSPEC_HOTPATCH OutputDebugStringW( LPCWSTR str ) STRING strA; WARN( "%s\n", debugstr_w(str) ); + if (!str) return; RtlInitUnicodeString( &strW, str ); if (!RtlUnicodeStringToAnsiString( &strA, &strW, TRUE )) -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10933
From: Matthias Gorzellik <matthias.gorzellik@gmail.com> --- dlls/kernel32/tests/debugger.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/dlls/kernel32/tests/debugger.c b/dlls/kernel32/tests/debugger.c index 478eaee9793..489cb535b72 100644 --- a/dlls/kernel32/tests/debugger.c +++ b/dlls/kernel32/tests/debugger.c @@ -2435,6 +2435,10 @@ static void test_OutputDebugString(void) pOutputDebugStringA("test"); ok(GetLastError() == 0xdeadbeef, "got %ld.\n", GetLastError()); + SetLastError(0xdeadbeef); + OutputDebugStringW(NULL); + ok(GetLastError() == 0xdeadbeef, "got %ld.\n", GetLastError()); + SetLastError(0xdeadbeef); OutputDebugStringW(L"test"); ok(GetLastError() == 0xdeadbeef, "got %ld.\n", GetLastError()); -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10933
On Mon May 18 13:00:54 2026 +0000, Jinoh Kang wrote:
This would need tests. Is NULL string skipped entirely? Or coerced to empty (but valud) string and passed to the debugger regardless. NULL string seems to be skipped entirely, it doesn't appear in Sysinternals DebugView. I've updated the MR with a test case.
-- https://gitlab.winehq.org/wine/wine/-/merge_requests/10933#note_140364
participants (2)
-
Matthias Gorzellik -
Matthias Gorzellik (@gotzl)