[utils,proxy] refactor proxy_parse_uri

* eliminate deadstore warnings
* fix missing input checks
This commit is contained in:
akallabeth 2024-09-30 20:18:41 +02:00
parent 8a0194c105
commit a1a8846ad2
No known key found for this signature in database
GPG Key ID: A49454A3FC909FD5
2 changed files with 18 additions and 4 deletions

View File

@ -22,12 +22,20 @@
#define FREERDP_PROXY_UTILS_H
#include <freerdp/api.h>
#include <freerdp/settings.h>
#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

View File

@ -19,6 +19,7 @@
#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <openssl/err.h>
@ -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;
}