Fixed domain and regex match.
@@ -149,10 +149,19 @@ static BOOL check_no_proxy(rdpSettings* settings, const char* no_proxy)
char* current;
char* copy;
size_t host_len;
+ struct sockaddr_in sa4;
+ struct sockaddr_in6 sa6;
+ BOOL is_ipv4 = FALSE;
+ BOOL is_ipv6 = FALSE;
if (!no_proxy || !settings)
return FALSE;
+ if (inet_pton(AF_INET, settings->ServerHostname, &sa4.sin_addr) == 1)
+ is_ipv4 = TRUE;
+ else if (inet_pton(AF_INET6, settings->ServerHostname, &sa6.sin6_addr) == 1)
+ is_ipv6 = TRUE;
+
host_len = strlen(settings->ServerHostname);
copy = _strdup(no_proxy);
@@ -175,8 +184,9 @@ static BOOL check_no_proxy(rdpSettings* settings, const char* no_proxy)
if (host_len >= currentlen)
{
const size_t offset = host_len + 1 - currentlen;
+ const char* name = settings->ServerHostname + offset;
- if (strncmp(current + 1, settings->ServerHostname + offset, currentlen - 1) == 0)
+ if (strncmp(current + 1, name, currentlen - 1) == 0)
result = TRUE;
}
}
@@ -185,23 +195,20 @@ static BOOL check_no_proxy(rdpSettings* settings, const char* no_proxy)
if (strncmp(current, settings->ServerHostname, currentlen - 1) == 0)
result = TRUE;
}
- else
+ else if (current[0] == '.') /* Only compare if the no_proxy variable contains a whole domain. */
{
- if (strcmp(current, settings->ServerHostname) == 0)
- result = TRUE; /* exact match */
- else
+ if (host_len > currentlen)
{
- struct sockaddr_in sa4;
- struct sockaddr_in6 sa6;
- BOOL is_ipv4 = FALSE;
- BOOL is_ipv6 = FALSE;
-
- if (inet_pton(AF_INET, settings->ServerHostname, &sa4.sin_addr) == 1)
- is_ipv4 = TRUE;
- else if (inet_pton(AF_INET6, settings->ServerHostname, &sa6.sin6_addr) == 1)
- is_ipv6 = TRUE;
+ const size_t offset = host_len - currentlen;
+ const char* name = settings->ServerHostname + offset;
- if (is_ipv4 || is_ipv6)
+ if (strncmp(current, name, currentlen) == 0)
+ result = TRUE; /* right-aligned match for host names */
+ }
+ }
+ else if (strcmp(current, settings->ServerHostname) == 0)
+ result = TRUE; /* exact match */
+ else if (is_ipv4 || is_ipv6)
{
char* rangedelim = strchr(current, '/');
@@ -234,22 +241,9 @@ static BOOL check_no_proxy(rdpSettings* settings, const char* no_proxy)
else
WLog_WARN(TAG, "NO_PROXY invalid entry %s", current);
}
- else if (!strncmp(current, settings->ServerHostname, currentlen))
+ else if (strncmp(current, settings->ServerHostname, currentlen) == 0)
result = TRUE; /* left-aligned match for IPs */
}
- else if (current[0] == '.') /* Only compare if the no_proxy variable contains a whole domain. */
- {
- if (host_len >= currentlen)
- {
- const size_t offset = host_len - currentlen;
-
- if (!strncmp(current, settings->ServerHostname + offset,
- currentlen))
- result = TRUE; /* right-aligned match for host names */
- }
- }
- }
- }
}
current = strtok(NULL, delimiter);
