From e1e3b8aa3de233558be1f4cbca12a6ffc7d0a688 Mon Sep 17 00:00:00 2001 From: Timo Kreuzer Date: Tue, 12 May 2026 12:28:39 +0300 Subject: [PATCH] [KERNEL32] Check for NULL lpBytesReturned Add NULL check for lpBytesReturned to match Windows 8+ behavior, which Wine code relies on. --- dll/win32/kernel32/client/file/deviceio.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/dll/win32/kernel32/client/file/deviceio.c b/dll/win32/kernel32/client/file/deviceio.c index bfcf575618d..cdc82a82c01 100644 --- a/dll/win32/kernel32/client/file/deviceio.c +++ b/dll/win32/kernel32/client/file/deviceio.c @@ -264,13 +264,16 @@ DeviceIoControl(IN HANDLE hDevice, /* Check for success */ if (NT_SUCCESS(Status)) { - /* Return the byte count */ - *lpBytesReturned = Iosb.Information; + /* Windows 2003 and Vista do not check for lpBytesReturned == NULL, + * but Windows 8+ does. Avoid crashing. */ + if (lpBytesReturned != NULL) + *lpBytesReturned = Iosb.Information; } else { /* Check for informational or warning failure */ - if (!NT_ERROR(Status)) *lpBytesReturned = Iosb.Information; + if (!NT_ERROR(Status) && (lpBytesReturned != NULL)) + *lpBytesReturned = Iosb.Information; /* Return a failure */ BaseSetLastNTError(Status);