2

Closed

RtlGetLastErrorString() returns empty string for invalidate parameter

description

NTSTATUS status = LhInstallHook(NULL, NULL, NULL, NULL);
RtlGetLastErrorString() => ""


diagnose
it seems that
LhInstallHook calls
#define THROW(code, Msg)        { NtStatus = (code); RtlSetLastError(GetLastError(), Msg); goto THROW_OUTRO; }
yet for simply invalid pointer, GetLastError() is 0
in RtlSetLastError
void RtlSetLastError(LONG InCode, WCHAR* InMessage)
{
LastErrorCode = InCode;

if(InCode == STATUS_SUCCESS) <- because GetLastError()  is 0
    LastError = L""; <- this line is executed instead of the else part
else
    LastError = (PWCHAR)InMessage;
}

suggested fix would be

void RtlSetLastError(LONG InCode, WCHAR* InMessage)
{
LastErrorCode = InCode;
LastError = (PWCHAR)InMessage;
}

or
#define THROW(code, Msg)        { NtStatus = (code); RtlSetLastError(0xF0000000L | GetLastError(), Msg); goto THROW_OUTRO; }
Closed Feb 6, 2014 at 11:47 PM by spazzarama

comments

wrote Feb 6, 2014 at 11:47 PM

Fixed on changeset 73764

wrote Feb 6, 2014 at 11:47 PM