From d068ad2d699c199c503c692c8c0b7dee54cbd166 Mon Sep 17 00:00:00 2001 From: Christoph von Wittich Date: Sun, 18 Jan 2009 10:06:34 +0000 Subject: [PATCH] fix kernel32 console winetest crash svn path=/trunk/; revision=38879 --- reactos/dll/win32/kernel32/misc/console.c | 47 ++++++++++++++++++----- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/reactos/dll/win32/kernel32/misc/console.c b/reactos/dll/win32/kernel32/misc/console.c index 0d257b98b1b..438a91a4852 100644 --- a/reactos/dll/win32/kernel32/misc/console.c +++ b/reactos/dll/win32/kernel32/misc/console.c @@ -3763,6 +3763,7 @@ BOOL WINAPI SetConsoleIcon(HICON hicon) BOOL WINAPI SetConsoleInputExeNameW(LPCWSTR lpInputExeName) { + NTSTATUS Status = STATUS_SUCCESS; int lenName = lstrlenW(lpInputExeName); if(lenName < 1 || @@ -3776,8 +3777,16 @@ SetConsoleInputExeNameW(LPCWSTR lpInputExeName) RtlEnterCriticalSection(&ConsoleLock); _SEH2_TRY { - RtlCopyMemory(InputExeName, lpInputExeName, lenName * sizeof(WCHAR)); - InputExeName[lenName] = L'\0'; + _SEH2_TRY + { + RtlCopyMemory(InputExeName, lpInputExeName, lenName * sizeof(WCHAR)); + InputExeName[lenName] = L'\0'; + } + _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + Status = _SEH2_GetExceptionCode(); + } + _SEH2_END; } _SEH2_FINALLY { @@ -3785,6 +3794,12 @@ SetConsoleInputExeNameW(LPCWSTR lpInputExeName) } _SEH2_END; + if (!NT_SUCCESS(Status)) + { + SetLastErrorByStatus(Status); + return FALSE; + } + return TRUE; } @@ -3836,20 +3851,28 @@ SetConsoleInputExeNameA(LPCSTR lpInputExeName) DWORD WINAPI GetConsoleInputExeNameW(DWORD nBufferLength, LPWSTR lpBuffer) { + NTSTATUS Status = STATUS_SUCCESS; int lenName = 0; RtlEnterCriticalSection(&ConsoleLock); - _SEH2_TRY { - lenName = lstrlenW(InputExeName); - if(lenName >= (int)nBufferLength) + _SEH2_TRY { - /* buffer is not large enough, return the required size */ - SetLastError(ERROR_BUFFER_OVERFLOW); - lenName += 1; + lenName = lstrlenW(InputExeName); + if(lenName >= (int)nBufferLength) + { + /* buffer is not large enough, return the required size */ + SetLastError(ERROR_BUFFER_OVERFLOW); + lenName += 1; + } + RtlCopyMemory(lpBuffer, InputExeName, (lenName + 1) * sizeof(WCHAR)); } - RtlCopyMemory(lpBuffer, InputExeName, (lenName + 1) * sizeof(WCHAR)); + _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + Status = _SEH2_GetExceptionCode(); + } + _SEH2_END; } _SEH2_FINALLY { @@ -3857,6 +3880,12 @@ GetConsoleInputExeNameW(DWORD nBufferLength, LPWSTR lpBuffer) } _SEH2_END; + if (!NT_SUCCESS(Status)) + { + SetLastError(ERROR_BUFFER_OVERFLOW); + return lenName + 1; + } + return lenName; }