VirtualBox

Changeset 57603 in vbox


Ignore:
Timestamp:
Sep 3, 2015 8:26:47 AM (9 years ago)
Author:
vboxsync
Message:

IPRT/fileio-win.cpp: Follow-up fix to r102458: Use the undocumented VerifyConsoleIoHandle() function in kernel32.dll to verify that the given handle actually is a console I/O handle, as we cannot assume that GetStdHandle will actually return real console I/O handles.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/win/fileio-win.cpp

    r57598 r57603  
    4040#include <iprt/string.h>
    4141#include <iprt/err.h>
     42#include <iprt/ldr.h>
    4243#include <iprt/log.h>
    4344#include "internal/file.h"
     
    4950*   Defined Constants And Macros                                                                                                 *
    5051*********************************************************************************************************************************/
    51 
     52typedef BOOL WINAPI FNVERIFYCONSOLEIOHANDLE(HANDLE);
     53typedef FNVERIFYCONSOLEIOHANDLE *PFNVERIFYCONSOLEIOHANDLE; /* No, nobody fell on the keyboard, really! */
    5254
    5355/**
     
    851853                && (OSInfoEx.dwPlatformId == VER_PLATFORM_WIN32_NT)
    852854                && (OSInfoEx.dwMajorVersion <= 6)
    853                 && (OSInfoEx.dwMajorVersion <= 1))
     855                && (OSInfoEx.dwMinorVersion <= 1))
    854856            {
    855                 /* Do we want to query file information for one of the pseudo handles? Then skip. */
    856                 if (   hHandle == GetStdHandle(STD_INPUT_HANDLE)
    857                     || hHandle == GetStdHandle(STD_OUTPUT_HANDLE)
    858                     || hHandle == GetStdHandle(STD_ERROR_HANDLE))
     857                PFNVERIFYCONSOLEIOHANDLE pfnVerifyConsoleIoHandle = NULL;
     858
     859                /*
     860                 * As the standard I/O handles could have been overwritten by SetStdHandle() we cannot assume
     861                 * that GetStdHandle will actually return real console I/O handles.
     862                 *
     863                 * So try to dynamically load the undocumented VerifyConsoleIoHandle from kernel32.dll.
     864                 * This function will check if the given handle actually is a console I/O handle, and if so,
     865                 * we know that we have to ignore the ERROR_INVALID_HANDLE on Windows 7 or earlier.
     866                 *
     867                 */
     868                RTLDRMOD hKernel32 = NIL_RTLDRMOD;
     869                int rc2 = RTLdrLoadSystem("kernel32.dll", true /*fNoUnload*/, &hKernel32);
     870                if (RT_SUCCESS(rc2))
     871                    rc2 = RTLdrGetSymbol(hKernel32, "VerifyConsoleIoHandle", (void**)&pfnVerifyConsoleIoHandle);
     872
     873                if (RT_SUCCESS(rc2))
    859874                {
    860                     fIgnoreError = true;
     875                    AssertPtr(pfnVerifyConsoleIoHandle);
     876
     877                    /* Is the handle a console handle? Then ignore ERROR_INVALID_HANDLE. */
     878                    if (pfnVerifyConsoleIoHandle(hHandle))
     879                        fIgnoreError = true;
    861880                }
     881
     882                if (hKernel32 != NIL_RTLDRMOD)
     883                    RTLdrClose(hKernel32);
    862884            }
    863885
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette