Zebediah Figura : setupapi: Don't use the devnode to allocate driver keys.
Alexandre Julliard
julliard at winehq.org
Wed Jan 23 17:11:33 CST 2019
Module: wine
Branch: master
Commit: dca175b2565353e4ec99822f0590d4dabedf05b2
URL: https://source.winehq.org/git/wine.git/?a=commit;h=dca175b2565353e4ec99822f0590d4dabedf05b2
Author: Zebediah Figura <z.figura12 at gmail.com>
Date: Tue Jan 22 22:10:30 2019 -0600
setupapi: Don't use the devnode to allocate driver keys.
The devnode is a local handle, but driver keys should be unique to the
device. (Note that MSDN, confusingly, refers to this number as a "device
instance ID".)
Signed-off-by: Zebediah Figura <z.figura12 at gmail.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/setupapi/devinst.c | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/dlls/setupapi/devinst.c b/dlls/setupapi/devinst.c
index 855fa92..e577f83 100644
--- a/dlls/setupapi/devinst.c
+++ b/dlls/setupapi/devinst.c
@@ -527,7 +527,9 @@ static HKEY create_driver_key(struct device *device)
static const WCHAR formatW[] = {'%','0','4','u',0};
static const WCHAR slash[] = { '\\',0 };
HKEY class_key, key;
+ unsigned int i = 0;
WCHAR path[50];
+ DWORD dispos;
LONG l;
if ((key = open_driver_key(device, KEY_READ | KEY_WRITE)) != INVALID_HANDLE_VALUE)
@@ -543,12 +545,20 @@ static HKEY create_driver_key(struct device *device)
SETUPDI_GuidToString(&device->class, path);
strcatW(path, slash);
- sprintfW(path + strlenW(path), formatW, device->devnode);
- if (!(l = RegCreateKeyExW(class_key, path, 0, NULL, 0, KEY_READ | KEY_WRITE, NULL, &key, NULL)))
+ /* Allocate a new driver key, by finding the first integer value that's not
+ * already taken. */
+ for (;;)
{
- RegSetValueExW(device->key, Driver, 0, REG_SZ, (BYTE *)path, strlenW(path) * sizeof(WCHAR));
- RegCloseKey(class_key);
- return key;
+ sprintfW(path + 39, formatW, i++);
+ if ((l = RegCreateKeyExW(class_key, path, 0, NULL, 0, KEY_READ | KEY_WRITE, NULL, &key, &dispos)))
+ break;
+ else if (dispos == REG_CREATED_NEW_KEY)
+ {
+ RegSetValueExW(device->key, Driver, 0, REG_SZ, (BYTE *)path, strlenW(path) * sizeof(WCHAR));
+ RegCloseKey(class_key);
+ return key;
+ }
+ RegCloseKey(key);
}
ERR("Failed to create driver key, error %u.\n", l);
RegCloseKey(class_key);
More information about the wine-cvs
mailing list