diff options
author | Simon Rozman <simon@rozman.si> | 2020-10-31 18:13:36 +0100 |
---|---|---|
committer | Simon Rozman <simon@rozman.si> | 2020-10-31 19:11:57 +0100 |
commit | 60ad907b99ceca0dbeab6123dcc0a44d8bfad29d (patch) | |
tree | 2ad0307795fc31b3e3653199f2c1e70a98a88999 /api/registry.c | |
parent | api: fix up console writing for debug (diff) | |
download | wintun-60ad907b99ceca0dbeab6123dcc0a44d8bfad29d.tar.xz wintun-60ad907b99ceca0dbeab6123dcc0a44d8bfad29d.zip |
api: check buffer overflows in runtime
Signed-off-by: Simon Rozman <simon@rozman.si>
Diffstat (limited to 'api/registry.c')
-rw-r--r-- | api/registry.c | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/api/registry.c b/api/registry.c index 1428165..82e3020 100644 --- a/api/registry.c +++ b/api/registry.c @@ -62,15 +62,11 @@ OpenKeyWait(_In_ HKEY Key, _Inout_z_ WCHAR *Path, _In_ DWORD Access, _In_ ULONGL } WINTUN_STATUS -RegistryOpenKeyWait( - _In_ HKEY Key, - _In_z_count_c_(MAX_REG_PATH) const WCHAR *Path, - _In_ DWORD Access, - _In_ DWORD Timeout, - _Out_ HKEY *KeyOut) +RegistryOpenKeyWait(_In_ HKEY Key, _In_z_ const WCHAR *Path, _In_ DWORD Access, _In_ DWORD Timeout, _Out_ HKEY *KeyOut) { WCHAR Buf[MAX_REG_PATH]; - wcscpy_s(Buf, _countof(Buf), Path); + if (wcsncpy_s(Buf, _countof(Buf), Path, _TRUNCATE) == STRUNCATE) + return LOG(WINTUN_LOG_ERR, L"Registry path too long"), ERROR_INVALID_PARAMETER; return OpenKeyWait(Key, Buf, Access, GetTickCount64() + Timeout, KeyOut); } |