guard SetConsoleInputExeNameW() with SEH to properly release the console lock in case of failure

svn path=/trunk/; revision=12179
This commit is contained in:
Thomas Bluemel 2004-12-18 13:33:09 +00:00
parent 0ad5627d13
commit b79bb15644

View file

@ -1,4 +1,4 @@
/* $Id: console.c,v 1.86 2004/12/18 13:26:57 weiden Exp $ /* $Id: console.c,v 1.87 2004/12/18 13:33:09 weiden Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
@ -3422,6 +3422,7 @@ BOOL STDCALL SetConsoleIcon(HICON hicon)
BOOL STDCALL BOOL STDCALL
SetConsoleInputExeNameW(LPCWSTR lpInputExeName) SetConsoleInputExeNameW(LPCWSTR lpInputExeName)
{ {
BOOL Ret = FALSE;
int lenName = lstrlenW(lpInputExeName); int lenName = lstrlenW(lpInputExeName);
if(lenName < 1 || if(lenName < 1 ||
@ -3433,11 +3434,25 @@ SetConsoleInputExeNameW(LPCWSTR lpInputExeName)
} }
RtlEnterCriticalSection(&ConsoleLock); RtlEnterCriticalSection(&ConsoleLock);
RtlCopyMemory(InputExeName, lpInputExeName, lenName * sizeof(WCHAR)); /* wrap copying into SEH as we may copy from invalid buffer and in case of an
InputExeName[lenName] = L'\0'; exception the console lock would've never been released, which would cause
further calls (if the exception was handled by the caller) to recursively
acquire the lock... */
_SEH_TRY
{
RtlCopyMemory(InputExeName, lpInputExeName, lenName * sizeof(WCHAR));
InputExeName[lenName] = L'\0';
Ret = TRUE;
}
_SEH_HANDLE
{
lenName = 0;
SetLastErrorByStatus(_SEH_GetExceptionCode());
}
_SEH_END;
RtlLeaveCriticalSection(&ConsoleLock); RtlLeaveCriticalSection(&ConsoleLock);
return TRUE; return Ret;
} }