Files
Tavis Ormandy 2f1ac6b3a2 fix #64 - crash on startup
RegisterTraceGuidsW was incorrectly declared as using cdecl calling convention.
This was causing the stack to be misaligned, and then a security check failed.
Windows code will sometimes execute int 0x29 when an error is detected, this is
what was happening here.

Secondly, some code changed that used to check the return code of
GetEnvironmentVariable, but now ignores the return code and checks the value of
GetLastError. On Windows that would usually be set to ERROR_ENVVAR_NOT_FOUND if
a variable wasn't set - I never bothered setting it because nobody checked it,
but now it needs that.
2019-04-09 13:14:24 -07:00

31 lines
598 B
C

#include <stdint.h>
#include <stddef.h>
#include <string.h>
#include <stdbool.h>
#include <search.h>
#include "winnt_types.h"
#include "pe_linker.h"
#include "ntoskernel.h"
#include "log.h"
#include "winexports.h"
#include "util.h"
STATIC DWORD LastError;
STATIC DWORD WINAPI GetLastError(void)
{
DebugLog("GetLastError() => %#x", LastError);
return LastError;
}
void WINAPI SetLastError(DWORD dwErrCode)
{
//DebugLog("SetLastError(%#x)", dwErrCode);
LastError = dwErrCode;
}
DECLARE_CRT_EXPORT("GetLastError", GetLastError);
DECLARE_CRT_EXPORT("SetLastError", SetLastError);