From 2ce5f6f17c7e0bc4110b1da5ef5b3e93b843c98e Mon Sep 17 00:00:00 2001 From: akallabeth Date: Fri, 15 Jan 2021 10:41:12 +0100 Subject: [PATCH] Check drive to hotplug for already being redirected some hotplug implementations report the same drive multiple times. to avoid redirecting the same drive multiple times check if it is already in the list before adding. (cherry picked from commit 9e8d3fbbf5ad7bb75799a8aca9fafa9c2dcf7fd9) --- channels/rdpdr/client/rdpdr_main.c | 33 +++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/channels/rdpdr/client/rdpdr_main.c b/channels/rdpdr/client/rdpdr_main.c index 4201ccbe1..a1db3b9bc 100644 --- a/channels/rdpdr/client/rdpdr_main.c +++ b/channels/rdpdr/client/rdpdr_main.c @@ -736,6 +736,37 @@ static UINT handle_platform_mounts(hotplug_dev* dev_array, size_t* size) return ERROR_CALL_NOT_IMPLEMENTED; } +static BOOL device_already_plugged(rdpdrPlugin* rdpdr, const hotplug_dev* device) +{ + BOOL rc = FALSE; + int count, x; + ULONG_PTR* keys = NULL; + + if (!rdpdr || !device) + return TRUE; + if (!device->to_add) + return TRUE; + + ListDictionary_Lock(rdpdr->devman->devices); + count = ListDictionary_GetKeys(rdpdr->devman->devices, &keys); + for (x = 0; x < count; x++) + { + DEVICE_DRIVE_EXT* device_ext = + (DEVICE_DRIVE_EXT*)ListDictionary_GetItemValue(rdpdr->devman->devices, (void*)keys[x]); + + if (!device_ext || (device_ext->device.type != RDPDR_DTYP_FILESYSTEM) || !device_ext->path) + continue; + if (strcmp(device_ext->path, device->path) == 0) + { + rc = TRUE; + break; + } + } + free(keys); + ListDictionary_Unlock(rdpdr->devman->devices); + return rc; +} + /** * Function description * @@ -806,7 +837,7 @@ static UINT handle_hotplug(rdpdrPlugin* rdpdr) /* add new devices */ for (i = 0; i < size; i++) { - if (dev_array[i].to_add) + if (!device_already_plugged(rdpdr, &dev_array[i])) { RDPDR_DRIVE drive = { 0 }; char* name;