https://git.reactos.org/?p=reactos.git;a=commitdiff;h=7c66247343697b5f1fe67…
commit 7c66247343697b5f1fe67207f850d1d88f232932
Author: Eric Kohl <eric.kohl(a)reactos.org>
AuthorDate: Sun Dec 30 00:39:08 2018 +0100
Commit: Eric Kohl <eric.kohl(a)reactos.org>
CommitDate: Sun Dec 30 09:06:59 2018 +0100
[UMPNPMGR] PNP_GetDeviceListSize: Implement the buffer size calculation for given
enumerators and take care of the terminating double Unicode null character.
---
base/services/umpnpmgr/umpnpmgr.c | 70 +++++++++++++++++++++++++++++++++++++--
1 file changed, 68 insertions(+), 2 deletions(-)
diff --git a/base/services/umpnpmgr/umpnpmgr.c b/base/services/umpnpmgr/umpnpmgr.c
index 3c96571dad..bae7fdda21 100644
--- a/base/services/umpnpmgr/umpnpmgr.c
+++ b/base/services/umpnpmgr/umpnpmgr.c
@@ -746,12 +746,73 @@ GetDeviceInstanceListSize(
RegCloseKey(hDeviceKey);
/* Return the largest possible buffer size */
- *pulLength = (dwSubKeys * (wcslen(pszDevice) + 1 + dwMaxSubKeyLength + 1)) + 1;
+ *pulLength = dwSubKeys * (wcslen(pszDevice) + 1 + dwMaxSubKeyLength + 1);
return CR_SUCCESS;
}
+static
+CONFIGRET
+GetEnumeratorInstanceListSize(
+ _In_ LPCWSTR pszEnumerator,
+ _Out_ PULONG pulLength)
+{
+ WCHAR szDeviceBuffer[MAX_DEVICE_ID_LEN];
+ WCHAR szPathBuffer[512];
+ HKEY hEnumeratorKey;
+ DWORD dwIndex, dwDeviceLength, dwBufferLength;
+ DWORD dwError;
+ CONFIGRET ret = CR_SUCCESS;
+
+ *pulLength = 0;
+
+ /* Open the enumerator key */
+ dwError = RegOpenKeyExW(hEnumKey,
+ pszEnumerator,
+ 0,
+ KEY_ENUMERATE_SUB_KEYS,
+ &hEnumeratorKey);
+ if (dwError != ERROR_SUCCESS)
+ {
+ DPRINT("Failed to open the enumerator key (Error %lu)\n", dwError);
+ return CR_REGISTRY_ERROR;
+ }
+
+ for (dwIndex = 0; ; dwIndex++)
+ {
+ dwDeviceLength = MAX_DEVICE_ID_LEN;
+ dwError = RegEnumKeyExW(hEnumeratorKey,
+ dwIndex,
+ szDeviceBuffer,
+ &dwDeviceLength,
+ NULL,
+ NULL,
+ NULL,
+ NULL);
+ if (dwError != ERROR_SUCCESS)
+ break;
+
+ wsprintf(szPathBuffer, L"%s\\%s", pszEnumerator, szDeviceBuffer);
+ DPRINT("Path: %S\n", szPathBuffer);
+
+ ret = GetDeviceInstanceListSize(szPathBuffer, &dwBufferLength);
+ if (ret != CR_SUCCESS)
+ {
+ *pulLength = 0;
+ break;
+ }
+
+ *pulLength += dwBufferLength;
+ }
+
+ /* Close the enumerator key */
+ RegCloseKey(hEnumeratorKey);
+
+ return ret;
+}
+
+
/* Function 11 */
DWORD
WINAPI
@@ -840,7 +901,8 @@ PNP_GetDeviceListSize(
}
else
{
- ret = CR_CALL_NOT_IMPLEMENTED;
+ ret = GetEnumeratorInstanceListSize(pszFilter,
+ pulLength);
}
}
else /* CM_GETIDLIST_FILTER_NONE */
@@ -848,6 +910,10 @@ PNP_GetDeviceListSize(
ret = CR_CALL_NOT_IMPLEMENTED;
}
+ /* Add one character for the terminating double UNICODE_NULL */
+ if (ret == CR_SUCCESS)
+ (*pulLength) += 1;
+
return ret;
}