commit b351266059e566afe7838cef18d7ea9de15d65f2
Author: Francois Gouget <fgouget@free.fr>
Date:   Thu Sep 1 14:54:10 2011 +0200

    kernel32: Make sure the console functions fail if not given a console handle.
    
    FlushConsoleInputBuffer(), ReadConsoleInputW(), WriteConsoleW() and SetConsoleDisplayMode() need and were missing an explicit check.

diff --git a/dlls/kernel32/console.c b/dlls/kernel32/console.c
index bab2322..ddb152b 100644
--- a/dlls/kernel32/console.c
+++ b/dlls/kernel32/console.c
@@ -1236,6 +1236,11 @@ BOOL WINAPI FlushConsoleInputBuffer( HANDLE handle )
     enum read_console_input_return      last;
     INPUT_RECORD                        ir;
 
+    if (!is_console_handle(handle))
+    {
+        SetLastError(ERROR_INVALID_HANDLE);
+        return FALSE;
+    }
     while ((last = read_console_input(handle, &ir, 0)) == rci_gotone);
 
     return last == rci_timeout;
@@ -1699,6 +1704,11 @@ BOOL WINAPI ReadConsoleInputW(HANDLE hConsoleInput, PINPUT_RECORD lpBuffer,
     DWORD idx = 0;
     DWORD timeout = INFINITE;
 
+    if (!is_console_handle(hConsoleInput))
+    {
+        SetLastError(ERROR_INVALID_HANDLE);
+        return FALSE;
+    }
     if (!nLength)
     {
         if (lpNumberOfEventsRead) *lpNumberOfEventsRead = 0;
@@ -2356,6 +2366,11 @@ BOOL WINAPI WriteConsoleW(HANDLE hConsoleOutput, LPCVOID lpBuffer, DWORD nNumber
 	  hConsoleOutput, debugstr_wn(lpBuffer, nNumberOfCharsToWrite),
 	  nNumberOfCharsToWrite, lpNumberOfCharsWritten, lpReserved);
 
+    if (!is_console_handle(hConsoleOutput))
+    {
+        SetLastError(ERROR_INVALID_HANDLE);
+        return FALSE;
+    }
     if (lpNumberOfCharsWritten) *lpNumberOfCharsWritten = 0;
 
     if ((fd = get_console_bare_fd(hConsoleOutput)) != -1)
@@ -2911,6 +2926,11 @@ BOOL WINAPI SetConsoleDisplayMode(HANDLE hConsoleOutput, DWORD dwFlags,
 {
     TRACE("(%p, %x, (%d, %d))\n", hConsoleOutput, dwFlags,
           lpNewScreenBufferDimensions->X, lpNewScreenBufferDimensions->Y);
+    if (!is_console_handle(hConsoleOutput))
+    {
+        SetLastError(ERROR_INVALID_HANDLE);
+        return FALSE;
+    }
     if (dwFlags == 1)
     {
         /* We cannot switch to fullscreen */
