server/proxy: set ps->thread to NULL on disconnect
authorkubistika <kmizrachi18@gmail.com>
Tue, 11 Jun 2019 15:54:10 +0000 (18:54 +0300)
committerakallabeth <akallabeth@users.noreply.github.com>
Wed, 26 Jun 2019 12:25:07 +0000 (14:25 +0200)
freerdp_abort_connect calls the proxy's client stop function,
that closes the thread handle. if it already closed by the server,
a segfault will occur because CloseHandle will try to access free()'ed
memory.

server/proxy/pf_server.c

index 98e2ba1..6894e15 100644 (file)
 
 static void pf_server_handle_client_disconnection(freerdp_peer* client)
 {
-       pServerContext* ps;
-       proxyData* pdata;
-       rdpContext* pc;
-       ps = (pServerContext*)client->context;
-       pc = (rdpContext*) ps->pdata->pc;
-       pdata = ps->pdata;
-       WLog_INFO(TAG, "Client %s disconnected; closing proxy's client <> target server connection %s",
+       pServerContext* ps = (pServerContext*)client->context;
+       rdpContext* pc = (rdpContext*) ps->pdata->pc;
+       proxyData* pdata = ps->pdata;
+       WLog_INFO(TAG, "Connection with %s was closed; closing proxy's client <> target server connection %s",
                  client->hostname, pc->settings->ServerHostname);
        /* Mark connection closed for sContext */
        SetEvent(pdata->connectionClosed);
@@ -70,6 +67,7 @@ static void pf_server_handle_client_disconnection(freerdp_peer* client)
        WLog_DBG(TAG, "Waiting for proxy's client thread to finish");
        WaitForSingleObject(ps->thread, INFINITE);
        CloseHandle(ps->thread);
+       ps->thread = NULL;
 }
 
 static BOOL pf_server_parse_target_from_routing_token(rdpContext* context,