aboutsummaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2020-10-31 17:07:03 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2020-11-01 00:00:14 +0100
commitb65e35569befadafa7f82db8b50b710540007298 (patch)
tree2eb9d0390e94ee928f816d7a2e954882246793f8 /api
parentapi: check buffer overflows in runtime (diff)
downloadwintun-b65e35569befadafa7f82db8b50b710540007298.tar.xz
wintun-b65e35569befadafa7f82db8b50b710540007298.zip
api: account for nt path to module
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'api')
-rw-r--r--api/adapter.c22
1 files changed, 8 insertions, 14 deletions
diff --git a/api/adapter.c b/api/adapter.c
index fa6d201..2948a62 100644
--- a/api/adapter.c
+++ b/api/adapter.c
@@ -1026,7 +1026,7 @@ RunningWintunVersion(void)
{
DWORDLONG Version = 0;
PRTL_PROCESS_MODULES Modules;
- ULONG BufferSize = 2048;
+ ULONG BufferSize = 128 * 1024;
for (;;)
{
Modules = HeapAlloc(ModuleHeap, 0, BufferSize);
@@ -1044,21 +1044,15 @@ RunningWintunVersion(void)
LOG(WINTUN_LOG_ERR, L"Failed to enumerate drivers");
return Version;
}
- for (ULONG i = 0; i < Modules->NumberOfModules; ++i)
+ for (ULONG i = Modules->NumberOfModules; i-- > 0;)
{
- if (!_stricmp(
- (const char *)&Modules->Modules[i].FullPathName[Modules->Modules[i].OffsetToFileName], "wintun.sys"))
+ const char *NtPath = (const char *)Modules->Modules[i].FullPathName;
+ if (!_stricmp(&NtPath[Modules->Modules[i].OffsetToFileName], "wintun.sys"))
{
- size_t Size = strlen((const char *)Modules->Modules[i].FullPathName) + 1;
- WCHAR *FilePathName = HeapAlloc(ModuleHeap, 0, Size * 2);
- if (!FilePathName)
- {
- LOG(WINTUN_LOG_ERR, L"Out of memory");
- goto out;
- }
- mbstowcs_s(&Size, FilePathName, Size, (const char *)Modules->Modules[i].FullPathName, _TRUNCATE);
- Version = VersionOfFile(FilePathName);
- HeapFree(ModuleHeap, 0, FilePathName);
+ WCHAR FilePath[MAX_PATH * 3 + 15];
+ if (_snwprintf_s(FilePath, _countof(FilePath), _TRUNCATE, L"\\\\?\\GLOBALROOT%S", NtPath) == -1)
+ continue;
+ Version = VersionOfFile(FilePath);
goto out;
}
}