From 6ac4cad8dd12f1f90ea4073ddb14f0cbae7e300c Mon Sep 17 00:00:00 2001 From: akallabeth Date: Thu, 7 Oct 2021 13:43:12 +0200 Subject: [PATCH] Settings fixes (#7335) * Fix temporary settings allocation for command line Detection of legacy command line requires a temporary settings struct. This was previously manyally allocated instead of using freerdp_settings_new and freerdp_settings_free. * Fixed CommandLineParseCommaSeparatedValuesEx The name argument was not copied into the returned array. --- client/common/compatibility.c | 7 +++---- winpr/libwinpr/utils/cmdline.c | 13 ++++++++++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/client/common/compatibility.c b/client/common/compatibility.c index da82d06fc..f97a86835 100644 --- a/client/common/compatibility.c +++ b/client/common/compatibility.c @@ -422,7 +422,7 @@ int freerdp_detect_old_command_line_syntax(int argc, char** argv, size_t* count) flags = COMMAND_LINE_SEPARATOR_SPACE | COMMAND_LINE_SILENCE_PARSER; flags |= COMMAND_LINE_SIGIL_DASH | COMMAND_LINE_SIGIL_DOUBLE_DASH; flags |= COMMAND_LINE_SIGIL_NOT_ESCAPED; - settings = (rdpSettings*)calloc(1, sizeof(rdpSettings)); + settings = freerdp_settings_new(0); if (!settings) return -1; @@ -433,7 +433,7 @@ int freerdp_detect_old_command_line_syntax(int argc, char** argv, size_t* count) if (status < 0) { - free(settings); + freerdp_settings_free(settings); return status; } @@ -468,8 +468,7 @@ int freerdp_detect_old_command_line_syntax(int argc, char** argv, size_t* count) detect_status = 1; } - free(settings->ServerHostname); - free(settings); + freerdp_settings_free(settings); return detect_status; } int freerdp_client_parse_old_command_line_arguments(int argc, char** argv, rdpSettings* settings) diff --git a/winpr/libwinpr/utils/cmdline.c b/winpr/libwinpr/utils/cmdline.c index 01b7f6e4e..f9b0960e6 100644 --- a/winpr/libwinpr/utils/cmdline.c +++ b/winpr/libwinpr/utils/cmdline.c @@ -490,7 +490,7 @@ char** CommandLineParseCommaSeparatedValuesEx(const char* name, const char* list size_t nArgs; size_t index; size_t nCommas; - size_t prefix, len; + size_t prefix, len, namelen = 0; nCommas = 0; if (count == NULL) @@ -535,7 +535,9 @@ char** CommandLineParseCommaSeparatedValuesEx(const char* name, const char* list prefix = (nArgs + 1UL) * sizeof(char*); len = strlen(list); - p = (char**)calloc(len + prefix + 1, sizeof(char*)); + if (name) + namelen = strlen(name); + p = (char**)calloc(len + prefix + 1 + namelen + 1, sizeof(char*)); if (!p) return NULL; @@ -544,7 +546,12 @@ char** CommandLineParseCommaSeparatedValuesEx(const char* name, const char* list memcpy(str, list, len); if (name) - p[0] = (char*)name; + { + char* namestr = &((char*)p)[prefix + len + 1]; + memcpy(namestr, name, namelen); + + p[0] = namestr; + } for (index = name ? 1 : 0; index < nArgs; index++) {