Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/taviso/loadlibrary.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTavis Ormandy <taviso@gmail.com>2019-04-09 23:14:24 +0300
committerTavis Ormandy <taviso@gmail.com>2019-04-09 23:14:24 +0300
commit2f1ac6b3a20a993fe4b720123e8a8444c04661ee (patch)
treef2a3605df1e1bc3b4615c6fbeaee1fec9b17e818
parentf7adbda5f48a25b846ec0de0efdf6cd104661af1 (diff)
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.
-rw-r--r--peloader/winapi/Environment.c6
-rw-r--r--peloader/winapi/EventTracing.c4
-rw-r--r--peloader/winapi/GetLastError.c2
-rw-r--r--peloader/winapi/SystemTime.c5
4 files changed, 14 insertions, 3 deletions
diff --git a/peloader/winapi/Environment.c b/peloader/winapi/Environment.c
index ba1cc23..cccb685 100644
--- a/peloader/winapi/Environment.c
+++ b/peloader/winapi/Environment.c
@@ -14,6 +14,10 @@
#include "util.h"
#include "winstrings.h"
+#define ERROR_ENVVAR_NOT_FOUND 203
+
+extern void WINAPI SetLastError(DWORD dwErrCode);
+
WCHAR EnvironmentStrings[] =
L"ALLUSERSPROFILE=AllUsersProfile\0"
L"ALLUSERSAPPDATA=AllUsersAppdata\0"
@@ -49,6 +53,8 @@ STATIC DWORD WINAPI GetEnvironmentVariableW(PWCHAR lpName, PVOID lpBuffer, DWORD
memcpy(lpBuffer, L"1", sizeof(L"1"));
} else if (strcmp(AnsiName, "MP_METASTORE_DISABLE") == 0) {
memcpy(lpBuffer, L"1", sizeof(L"1"));
+ } else {
+ SetLastError(ERROR_ENVVAR_NOT_FOUND);
}
free(AnsiName);
diff --git a/peloader/winapi/EventTracing.c b/peloader/winapi/EventTracing.c
index d5deec3..aa41406 100644
--- a/peloader/winapi/EventTracing.c
+++ b/peloader/winapi/EventTracing.c
@@ -12,7 +12,7 @@
#include "winexports.h"
#include "util.h"
-STATIC ULONG RegisterTraceGuidsW(PVOID RequestAddress,
+STATIC ULONG WINAPI RegisterTraceGuidsW(PVOID RequestAddress,
PVOID RequestContext,
PVOID ControlGuid,
ULONG GuidCount,
@@ -34,7 +34,7 @@ STATIC ULONG RegisterTraceGuidsW(PVOID RequestAddress,
return STATUS_SUCCESS;
}
-STATIC ULONG UnregisterTraceGuids(HANDLE RegistrationHandle)
+STATIC ULONG WINAPI UnregisterTraceGuids(HANDLE RegistrationHandle)
{
DebugLog("%p", RegistrationHandle);
return STATUS_SUCCESS;
diff --git a/peloader/winapi/GetLastError.c b/peloader/winapi/GetLastError.c
index a480c5c..6882bb4 100644
--- a/peloader/winapi/GetLastError.c
+++ b/peloader/winapi/GetLastError.c
@@ -15,7 +15,7 @@ STATIC DWORD LastError;
STATIC DWORD WINAPI GetLastError(void)
{
- //DebugLog("GetLastError() => %#x", LastError);
+ DebugLog("GetLastError() => %#x", LastError);
return LastError;
}
diff --git a/peloader/winapi/SystemTime.c b/peloader/winapi/SystemTime.c
index f1adb3f..da831c7 100644
--- a/peloader/winapi/SystemTime.c
+++ b/peloader/winapi/SystemTime.c
@@ -22,6 +22,8 @@ typedef struct _SYSTEMTIME {
WORD wMilliseconds;
} SYSTEMTIME, *PSYSTEMTIME;
+extern void WINAPI SetLastError(DWORD dwErrCode);
+
// These routines are called to check if signing certificates have expired, so
// should return similar values.
@@ -51,6 +53,7 @@ STATIC VOID WINAPI GetSystemTimeAsFileTime(PVOID lpSystemTimeAsFileTime)
STATIC BOOL WINAPI QueryPerformanceCounter(PVOID lpPerformanceCount)
{
+ SetLastError(0);
return FALSE;
}
@@ -61,11 +64,13 @@ STATIC DWORD WINAPI GetTickCount(VOID)
STATIC BOOL WINAPI QueryPerformanceFrequency(PVOID lpFrequency)
{
+ SetLastError(0);
return FALSE;
}
STATIC BOOL WINAPI GetProcessTimes(HANDLE hProcess, PFILETIME lpCreationTime, PFILETIME lpExitTime, PFILETIME lpKernelTime, PFILETIME lpUserTime)
{
+ SetLastError(0);
DebugLog("");
return FALSE;
}