aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rozman <simon@rozman.si>2020-07-24 08:10:00 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2020-10-30 16:50:59 +0100
commit28c135b8e17385db724ea83a4341fa69178b15b2 (patch)
treecfc52172737135e8078b7d610be9e86c4774ca66
parentapi: fix SPDRP_DEVICEDESC zero-termination (diff)
downloadwintun-28c135b8e17385db724ea83a4341fa69178b15b2.tar.xz
wintun-28c135b8e17385db724ea83a4341fa69178b15b2.zip
api: tighten maximum registry key path length
Maximum registry key path length is not 260 (MAX_PATH), but 255 (256 incl. zero terminator). Signed-off-by: Simon Rozman <simon@rozman.si>
-rw-r--r--api/api.h8
-rw-r--r--api/devmgmt.c20
-rw-r--r--api/registry.c6
3 files changed, 19 insertions, 15 deletions
diff --git a/api/api.h b/api/api.h
index 3998123..e409b8b 100644
--- a/api/api.h
+++ b/api/api.h
@@ -38,16 +38,20 @@ NciInit();
void
NciCleanup();
+#define MAX_REG_PATH \
+ 256 /* Maximum registry path length \
+ https://support.microsoft.com/en-us/help/256986/windows-registry-information-for-advanced-users */
+
WINTUN_STATUS
RegistryOpenKeyWait(
_In_ HKEY Key,
- _In_z_count_c_(MAX_PATH) const WCHAR *Path,
+ _In_z_count_c_(MAX_REG_PATH) const WCHAR *Path,
_In_ DWORD Access,
_In_ DWORD Timeout,
_Out_ HKEY *KeyOut);
WINTUN_STATUS
-RegistryWaitForKey(_In_ HKEY Key, _In_z_count_c_(MAX_PATH) const WCHAR *Path, _In_ DWORD Timeout);
+RegistryWaitForKey(_In_ HKEY Key, _In_z_count_c_(MAX_REG_PATH) const WCHAR *Path, _In_ DWORD Timeout);
WINTUN_STATUS
RegistryGetString(_Inout_ WCHAR **Buf, _In_ DWORD Len, _In_ DWORD ValueType);
diff --git a/api/devmgmt.c b/api/devmgmt.c
index 83a14be..4604bf5 100644
--- a/api/devmgmt.c
+++ b/api/devmgmt.c
@@ -510,11 +510,11 @@ cleanupKey:
* Returns the device-level registry key path.
*/
static void
-GetDeviceRegPath(_In_ const WINTUN_ADAPTER *Adapter, _Out_cap_c_(MAX_PATH + MAX_INSTANCE_ID) WCHAR *Path)
+GetDeviceRegPath(_In_ const WINTUN_ADAPTER *Adapter, _Out_cap_c_(MAX_REG_PATH) WCHAR *Path)
{
_snwprintf_s(
Path,
- MAX_PATH + MAX_INSTANCE_ID,
+ MAX_REG_PATH,
_TRUNCATE,
L"SYSTEM\\CurrentControlSet\\Enum\\%.*s",
MAX_INSTANCE_ID,
@@ -525,12 +525,12 @@ GetDeviceRegPath(_In_ const WINTUN_ADAPTER *Adapter, _Out_cap_c_(MAX_PATH + MAX_
* Returns the adapter-specific TCP/IP network registry key path.
*/
static void
-GetTcpipAdapterRegPath(_In_ const WINTUN_ADAPTER *Adapter, _Out_cap_c_(MAX_PATH) WCHAR *Path)
+GetTcpipAdapterRegPath(_In_ const WINTUN_ADAPTER *Adapter, _Out_cap_c_(MAX_REG_PATH) WCHAR *Path)
{
WCHAR Guid[MAX_GUID_STRING_LEN];
_snwprintf_s(
Path,
- MAX_PATH,
+ MAX_REG_PATH,
_TRUNCATE,
L"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Adapters\\%.*s",
StringFromGUID2(&Adapter->CfgInstanceID, Guid, _countof(Guid)),
@@ -541,11 +541,11 @@ GetTcpipAdapterRegPath(_In_ const WINTUN_ADAPTER *Adapter, _Out_cap_c_(MAX_PATH)
* Returns the interface-specific TCP/IP network registry key path.
*/
static WINTUN_STATUS
-GetTcpipInterfaceRegPath(_In_ const WINTUN_ADAPTER *Adapter, _Out_cap_c_(MAX_PATH) WCHAR *Path)
+GetTcpipInterfaceRegPath(_In_ const WINTUN_ADAPTER *Adapter, _Out_cap_c_(MAX_REG_PATH) WCHAR *Path)
{
DWORD Result;
HKEY TcpipAdapterRegKey;
- WCHAR TcpipAdapterRegPath[MAX_PATH];
+ WCHAR TcpipAdapterRegPath[MAX_REG_PATH];
GetTcpipAdapterRegPath(Adapter, TcpipAdapterRegPath);
Result = RegOpenKeyExW(HKEY_LOCAL_MACHINE, TcpipAdapterRegPath, 0, KEY_QUERY_VALUE, &TcpipAdapterRegKey);
if (Result != ERROR_SUCCESS)
@@ -559,7 +559,7 @@ GetTcpipInterfaceRegPath(_In_ const WINTUN_ADAPTER *Adapter, _Out_cap_c_(MAX_PAT
Result = ERROR_NETWORK_NOT_AVAILABLE;
goto cleanupPaths;
}
- _snwprintf_s(Path, MAX_PATH, _TRUNCATE, L"SYSTEM\\CurrentControlSet\\Services\\%s", Paths);
+ _snwprintf_s(Path, MAX_REG_PATH, _TRUNCATE, L"SYSTEM\\CurrentControlSet\\Services\\%s", Paths);
cleanupPaths:
HeapFree(GetProcessHeap(), 0, Paths);
cleanupTcpipAdapterRegKey:
@@ -743,7 +743,7 @@ WintunSetAdapterName(_In_ const WINTUN_ADAPTER *Adapter, _In_z_count_c_(MAX_ADAP
/* TODO: This should use NetSetup2 so that it doesn't get unset. */
HKEY DeviceRegKey;
- WCHAR DeviceRegPath[MAX_PATH + MAX_INSTANCE_ID];
+ WCHAR DeviceRegPath[MAX_REG_PATH];
GetDeviceRegPath(Adapter, DeviceRegPath);
Result = RegOpenKeyExW(HKEY_LOCAL_MACHINE, DeviceRegPath, 0, KEY_SET_VALUE, &DeviceRegKey);
if (Result != ERROR_SUCCESS)
@@ -1056,7 +1056,7 @@ WintunCreateAdapter(
goto cleanupNetDevRegKey;
HKEY TcpipAdapterRegKey;
- WCHAR TcpipAdapterRegPath[MAX_PATH];
+ WCHAR TcpipAdapterRegPath[MAX_REG_PATH];
GetTcpipAdapterRegPath(*Adapter, TcpipAdapterRegPath);
Result = RegistryOpenKeyWait(
HKEY_LOCAL_MACHINE,
@@ -1072,7 +1072,7 @@ WintunCreateAdapter(
HeapFree(Heap, 0, DummyStr);
HKEY TcpipInterfaceRegKey;
- WCHAR TcpipInterfaceRegPath[MAX_PATH];
+ WCHAR TcpipInterfaceRegPath[MAX_REG_PATH];
Result = GetTcpipInterfaceRegPath(*Adapter, TcpipInterfaceRegPath);
if (Result != ERROR_SUCCESS)
goto cleanupTcpipAdapterRegKey;
diff --git a/api/registry.c b/api/registry.c
index 157527c..7a68e58 100644
--- a/api/registry.c
+++ b/api/registry.c
@@ -66,18 +66,18 @@ OpenKeyWait(_In_ HKEY Key, _Inout_z_ WCHAR *Path, _In_ DWORD Access, _In_ ULONGL
WINTUN_STATUS
RegistryOpenKeyWait(
_In_ HKEY Key,
- _In_z_count_c_(MAX_PATH) const WCHAR *Path,
+ _In_z_count_c_(MAX_REG_PATH) const WCHAR *Path,
_In_ DWORD Access,
_In_ DWORD Timeout,
_Out_ HKEY *KeyOut)
{
- WCHAR Buf[MAX_PATH];
+ WCHAR Buf[MAX_REG_PATH];
wcscpy_s(Buf, _countof(Buf), Path);
return OpenKeyWait(Key, Buf, Access, GetTickCount64() + Timeout, KeyOut);
}
WINTUN_STATUS
-RegistryWaitForKey(_In_ HKEY Key, _In_z_count_c_(MAX_PATH) const WCHAR *Path, _In_ DWORD Timeout)
+RegistryWaitForKey(_In_ HKEY Key, _In_z_count_c_(MAX_REG_PATH) const WCHAR *Path, _In_ DWORD Timeout)
{
HKEY k;
DWORD Result = RegistryOpenKeyWait(Key, Path, KEY_NOTIFY, Timeout, &k);