From c4d72c6ad2f82147f5caa5e587d7eddbe98dbb5f Mon Sep 17 00:00:00 2001 From: kubistika Date: Sun, 12 May 2019 20:49:37 +0300 Subject: [PATCH] server/proxy: Refactor pf_server_parse_target_from_routing_token --- server/proxy/pf_server.c | 62 ++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/server/proxy/pf_server.c b/server/proxy/pf_server.c index e85b4da49..a34188da7 100644 --- a/server/proxy/pf_server.c +++ b/server/proxy/pf_server.c @@ -82,37 +82,43 @@ static BOOL pf_server_parse_target_from_routing_token(freerdp_peer* client, DWORD routing_token_length; const char* routing_token = freerdp_nego_get_routing_token(client->context, &routing_token_length); - if (routing_token && - (routing_token_length > prefix_len) && (routing_token_length < TARGET_MAX)) + if (routing_token == NULL) { - len = routing_token_length - prefix_len; - *target = malloc(len + 1); - - if (!(*target)) - return FALSE; - - CopyMemory(*target, routing_token + prefix_len, len); - *(*target + len) = '\0'; - colon = strchr(*target, ':'); - WLog_INFO(TAG, "Target [parsed from routing token]: %s", *target); - - if (colon) - { - /* port is specified */ - unsigned long p = strtoul(colon + 1, NULL, 10); - - if (p > USHRT_MAX) - return FALSE; - - *port = (DWORD)p; - *colon = '\0'; - } - - return TRUE; + /* no routing token */ + return FALSE; } - /* no routing token */ - return FALSE; + if ((routing_token_length <= prefix_len) || (routing_token_length >= TARGET_MAX)) + { + WLog_ERR(TAG, "pf_server_parse_target_from_routing_token: bad routing token length: %i", + routing_token_length); + return FALSE; + } + + len = routing_token_length - prefix_len; + *target = malloc(len + 1); + + if (!(*target)) + return FALSE; + + CopyMemory(*target, routing_token + prefix_len, len); + *(*target + len) = '\0'; + colon = strchr(*target, ':'); + WLog_INFO(TAG, "Target [parsed from routing token]: %s", *target); + + if (colon) + { + /* port is specified */ + unsigned long p = strtoul(colon + 1, NULL, 10); + + if (p > USHRT_MAX) + return FALSE; + + *port = (DWORD)p; + *colon = '\0'; + } + + return TRUE; } /* Event callbacks */