From a1a8846ad2322ef6042e2b4d3548aacae7a0dc90 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Mon, 30 Sep 2024 20:18:41 +0200 Subject: [PATCH] [utils,proxy] refactor proxy_parse_uri * eliminate deadstore warnings * fix missing input checks --- include/freerdp/utils/proxy_utils.h | 8 ++++++++ libfreerdp/core/proxy.c | 14 ++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/include/freerdp/utils/proxy_utils.h b/include/freerdp/utils/proxy_utils.h index 0bd510e9e..57b0ba540 100644 --- a/include/freerdp/utils/proxy_utils.h +++ b/include/freerdp/utils/proxy_utils.h @@ -22,12 +22,20 @@ #define FREERDP_PROXY_UTILS_H #include +#include #ifdef __cplusplus extern "C" { #endif + /** @brief parse a proxy environment variable string and populate settings from it + * + * @param settings the settings to populate, must not be \b NULL + * @param uri_in the proxy string to parse, must not be \b NULL + * + * @return \b TRUE if parsed successfully + */ FREERDP_API BOOL proxy_parse_uri(rdpSettings* settings, const char* uri_in); #ifdef __cplusplus diff --git a/libfreerdp/core/proxy.c b/libfreerdp/core/proxy.c index 17fff988f..d96127eff 100644 --- a/libfreerdp/core/proxy.c +++ b/libfreerdp/core/proxy.c @@ -19,6 +19,7 @@ #include #include +#include #include @@ -329,14 +330,16 @@ BOOL proxy_parse_uri(rdpSettings* settings, const char* uri_in) BOOL rc = FALSE; const char* protocol = ""; UINT16 port = 0; - char* p = NULL; - char* atPtr = NULL; + + if (!settings || !uri_in) + return FALSE; + char* uri_copy = _strdup(uri_in); char* uri = uri_copy; if (!uri) goto fail; - p = strstr(uri, "://"); + char* p = strstr(uri, "://"); if (p) { @@ -376,7 +379,7 @@ BOOL proxy_parse_uri(rdpSettings* settings, const char* uri_in) } /* uri is now [user:password@]hostname:port */ - atPtr = strrchr(uri, '@'); + char* atPtr = strrchr(uri, '@'); if (atPtr) { @@ -480,6 +483,9 @@ BOOL proxy_parse_uri(rdpSettings* settings, const char* uri_in) rc = TRUE; fail: + if (!rc) + WLog_WARN(TAG, "Failed to parse proxy configuration: %s://%s:%" PRIu16, protocol, uri, + port); free(uri_copy); return rc; }