diff options
author | Craig Hutchinson <54269136+CraigHutchinson@users.noreply.github.com> | 2021-06-08 20:03:43 +0200 |
---|---|---|
committer | Nathan Hjelm <hjelmn@google.com> | 2021-07-08 21:52:14 -0600 |
commit | a03058723a03080456814d5212c3caceacc58ae9 (patch) | |
tree | 4cb34f8bcc09d24af9945af7eb7ad21b64d57798 /libusb/os/windows_winusb.c | |
parent | 68289d0d038b42e177d50fec9e26b8175d302627 (diff) | |
download | libusb-a03058723a03080456814d5212c3caceacc58ae9.tar.gz |
windows: Allow GUID with and without trailing zeroes
Improve the GUID length check to accommodate the cases where the GUID
string fetched from registry does not have a trailing zero, or if a
multi-string entry, one or two trailing zeroes.
Closes #927
Signed-off-by: Craig Hutchinson <54269136+CraigHutchinson@users.noreply.github.com>
[Tormod: Use correct types and simplify comparisons]
Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
Signed-off-by: Nathan Hjelm <hjelmn@google.com>
Diffstat (limited to 'libusb/os/windows_winusb.c')
-rw-r--r-- | libusb/os/windows_winusb.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/libusb/os/windows_winusb.c b/libusb/os/windows_winusb.c index cdca6cb..1fdc703 100644 --- a/libusb/os/windows_winusb.c +++ b/libusb/os/windows_winusb.c @@ -1626,9 +1626,15 @@ static int winusb_get_device_list(struct libusb_context *ctx, struct discovered_ s = pRegQueryValueExA(key, "DeviceInterfaceGUID", NULL, ®_type, (LPBYTE)guid_string, &size); pRegCloseKey(key); - if ((s == ERROR_SUCCESS) && - (((reg_type == REG_SZ) && (size == (sizeof(guid_string) - sizeof(char)))) || - ((reg_type == REG_MULTI_SZ) && (size == sizeof(guid_string))))) { + if (s != ERROR_SUCCESS) { + usbi_warn(ctx, "unexpected error from pRegQueryValueExA for '%s'", dev_id); + break; + } + // https://docs.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regqueryvalueexa#remarks + // - "string may not have been stored with the proper terminating null characters" + // - "Note that REG_MULTI_SZ strings could have two terminating null characters" + if ((reg_type == REG_SZ && size >= sizeof(guid_string) - sizeof(char)) + || (reg_type == REG_MULTI_SZ && size >= sizeof(guid_string) - 2 * sizeof(char))) { if (nb_guids == guid_size) { new_guid_list = realloc((void *)guid_list, (guid_size + GUID_SIZE_STEP) * sizeof(void *)); if (new_guid_list == NULL) { @@ -1660,7 +1666,7 @@ static int winusb_get_device_list(struct libusb_context *ctx, struct discovered_ free(if_guid); } } - } else if (s == ERROR_SUCCESS) { + } else { usbi_warn(ctx, "unexpected type/size of DeviceInterfaceGUID for '%s'", dev_id); } break; |