diff options
author | Chris Dickens <christopher.a.dickens@gmail.com> | 2020-03-31 18:23:43 -0700 |
---|---|---|
committer | Chris Dickens <christopher.a.dickens@gmail.com> | 2020-03-31 18:23:43 -0700 |
commit | 3f6e8baa2baaa617a83c810c1ae1b49e4f4a6667 (patch) | |
tree | 62356dd7527621a09521c8955135a274378e651c | |
parent | 1ce667ff7be902e376647ea81d812b75f3e43a00 (diff) | |
download | libusb-3f6e8baa2baaa617a83c810c1ae1b49e4f4a6667.tar.gz |
Windows: Replace the sanitize_path() function with normalize_path()
Once upon a time the sanitize_path() function was needed to generate a
consistent path format in order to hash the resulting string for use as
session IDs. Since commit 71a779d078 ("Windows: Rework WinUSB
enumeration process to fix issues on Win8+"), this hashing method is no
longer used for session IDs, thus the sanitize_path() function was no
longer explicitly needed.
User lo1ol also reports in issue #633 that the function actually causes
issues with devices where there is a path component following the device
interface GUID. Rather than patching the function to fix this specific
behavior, just replace it with a simpler function that returns an
uppercased duplicate of the input string.
Closes #633, Closes #662
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
-rw-r--r-- | libusb/os/windows_winusb.c | 44 | ||||
-rw-r--r-- | libusb/version_nano.h | 2 |
2 files changed, 11 insertions, 35 deletions
diff --git a/libusb/os/windows_winusb.c b/libusb/os/windows_winusb.c index 67013d6..7e67176 100644 --- a/libusb/os/windows_winusb.c +++ b/libusb/os/windows_winusb.c @@ -128,43 +128,19 @@ static const char *guid_to_string(const GUID *guid) #endif /* - * Sanitize Microsoft's paths: convert to uppercase, add prefix and fix backslashes. - * Return an allocated sanitized string or NULL on error. + * Normalize Microsoft's paths: return a duplicate of the given path + * with all characters converted to uppercase */ -static char *sanitize_path(const char *path) +static char *normalize_path(const char *path) { - const char root_prefix[] = {'\\', '\\', '.', '\\'}; - size_t j, size; - char *ret_path; - size_t add_root = 0; + char *ret_path = _strdup(path); + char *p; - if (path == NULL) - return NULL; - - size = strlen(path) + 1; - - // Microsoft indiscriminately uses '\\?\', '\\.\', '##?#" or "##.#" for root prefixes. - if (!((size > 3) && (((path[0] == '\\') && (path[1] == '\\') && (path[3] == '\\')) - || ((path[0] == '#') && (path[1] == '#') && (path[3] == '#'))))) { - add_root = sizeof(root_prefix); - size += add_root; - } - - ret_path = malloc(size); if (ret_path == NULL) return NULL; - strcpy(&ret_path[add_root], path); - - // Ensure consistency with root prefix - memcpy(ret_path, root_prefix, sizeof(root_prefix)); - - // Same goes for '\' and '#' after the root prefix. Ensure '#' is used - for (j = sizeof(root_prefix); j < size; j++) { - ret_path[j] = (char)toupper((int)ret_path[j]); // Fix case too - if (ret_path[j] == '\\') - ret_path[j] = '#'; - } + for (p = ret_path; *p != '\0'; p++) + *p = (char)toupper((unsigned char)*p); return ret_path; } @@ -324,7 +300,7 @@ static int get_interface_details(struct libusb_context *ctx, HDEVINFO dev_info, return LIBUSB_ERROR_OTHER; } - *dev_interface_path = sanitize_path(dev_interface_details->DevicePath); + *dev_interface_path = normalize_path(dev_interface_details->DevicePath); free(dev_interface_details); if (*dev_interface_path == NULL) { @@ -2241,7 +2217,7 @@ static int winusbx_claim_interface(int sub_api, struct libusb_device_handle *dev SP_DEVICE_INTERFACE_DETAIL_DATA_A *dev_interface_details = NULL; HDEVINFO dev_info = INVALID_HANDLE_VALUE; SP_DEVINFO_DATA dev_info_data; - char *dev_path_no_guid = NULL; + char *dev_path_no_guid; char filter_path[] = "\\\\.\\libusb0-0000"; bool found_filter = false; HANDLE file_handle, winusb_handle; @@ -2278,7 +2254,7 @@ static int winusbx_claim_interface(int sub_api, struct libusb_device_handle *dev break; // ignore GUID part - dev_path_no_guid = sanitize_path(strtok(dev_interface_details->DevicePath, "{")); + dev_path_no_guid = strtok(dev_interface_details->DevicePath, "{"); if (dev_path_no_guid == NULL) continue; diff --git a/libusb/version_nano.h b/libusb/version_nano.h index 5028718..67bcc19 100644 --- a/libusb/version_nano.h +++ b/libusb/version_nano.h @@ -1 +1 @@ -#define LIBUSB_NANO 11483 +#define LIBUSB_NANO 11484 |