channels/rdpdr: fix potential robustness issues related to hotplug support
This commit is contained in:
parent
14b75d1b27
commit
374b5e4dcc
@ -434,15 +434,16 @@ static void* drive_hotplug_thread_func(void* arg)
|
||||
struct timeval tv;
|
||||
int rv;
|
||||
|
||||
rdpdr = (rdpdrPlugin *)arg;
|
||||
rdpdr = (rdpdrPlugin*) arg;
|
||||
|
||||
rdpdr->stop_event = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||
rdpdr->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||
|
||||
mfd = open("/proc/mounts", O_RDONLY, 0);
|
||||
|
||||
if (mfd < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: Unable to open /proc/mounts.");
|
||||
return NULL;
|
||||
fprintf(stderr, "ERROR: Unable to open /proc/mounts.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
FD_ZERO(&rfds);
|
||||
@ -452,7 +453,7 @@ static void* drive_hotplug_thread_func(void* arg)
|
||||
|
||||
while ((rv = select(mfd+1, NULL, NULL, &rfds, &tv)) >= 0)
|
||||
{
|
||||
if (WaitForSingleObject(rdpdr->stop_event, 0) == WAIT_OBJECT_0)
|
||||
if (WaitForSingleObject(rdpdr->stopEvent, 0) == WAIT_OBJECT_0)
|
||||
break;
|
||||
|
||||
if (FD_ISSET(mfd, &rfds))
|
||||
@ -467,13 +468,19 @@ static void* drive_hotplug_thread_func(void* arg)
|
||||
tv.tv_usec = 0;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void drive_hotplug_thread_terminate(rdpdrPlugin* rdpdr)
|
||||
{
|
||||
if (rdpdr->stop_event)
|
||||
SetEvent(rdpdr->stop_event);
|
||||
if (rdpdr->hotplugThread)
|
||||
{
|
||||
if (rdpdr->stopEvent)
|
||||
SetEvent(rdpdr->stopEvent);
|
||||
|
||||
WaitForSingleObject(rdpdr->hotplugThread, INFINITE);
|
||||
rdpdr->hotplugThread = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -493,11 +500,14 @@ static void rdpdr_process_connect(rdpdrPlugin* rdpdr)
|
||||
for (index = 0; index < settings->DeviceCount; index++)
|
||||
{
|
||||
device = settings->DeviceArray[index];
|
||||
if (strcmp(device->Name, "*") == 0)
|
||||
|
||||
if (device->Name && (strcmp(device->Name, "*") == 0))
|
||||
{
|
||||
rdpdr->hotplug_thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)drive_hotplug_thread_func, rdpdr, 0, NULL);
|
||||
rdpdr->hotplugThread = CreateThread(NULL, 0,
|
||||
(LPTHREAD_START_ROUTINE) drive_hotplug_thread_func, rdpdr, 0, NULL);
|
||||
continue;
|
||||
}
|
||||
|
||||
devman_load_device_service(rdpdr->devman, device);
|
||||
}
|
||||
}
|
||||
@ -939,8 +949,6 @@ static void rdpdr_virtual_channel_event_terminated(rdpdrPlugin* rdpdr)
|
||||
|
||||
drive_hotplug_thread_terminate(rdpdr);
|
||||
|
||||
WaitForSingleObject(rdpdr->hotplug_thread, INFINITE);
|
||||
|
||||
rdpdr->channelEntryPoints.pVirtualChannelClose(rdpdr->OpenHandle);
|
||||
|
||||
if (rdpdr->data_in)
|
||||
|
@ -54,11 +54,11 @@ struct rdpdr_plugin
|
||||
char computerName[256];
|
||||
|
||||
/* hotplug support */
|
||||
HANDLE hotplug_thread;
|
||||
HANDLE hotplugThread;
|
||||
#ifdef _WIN32
|
||||
HWND hotplug_wnd;
|
||||
#else
|
||||
HANDLE stop_event;
|
||||
HANDLE stopEvent;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user