cmd line: add missing checks

* strdup
* some allocs
This commit is contained in:
Bernhard Miklautz 2015-06-18 13:00:10 +02:00
parent 5de0e02c61
commit 1b8dd139a9
5 changed files with 308 additions and 83 deletions

View File

@ -216,6 +216,8 @@ int freerdp_client_print_command_line_help(int argc, char** argv)
{ {
length = (int)(strlen(arg->Name) + strlen(arg->Format) + 2); length = (int)(strlen(arg->Name) + strlen(arg->Format) + 2);
str = (char*) calloc(length + 1UL, sizeof(char)); str = (char*) calloc(length + 1UL, sizeof(char));
if (!str)
return -1;
sprintf_s(str, length + 1, "%s:%s", arg->Name, arg->Format); sprintf_s(str, length + 1, "%s:%s", arg->Name, arg->Format);
printf("%-20s", str); printf("%-20s", str);
free(str); free(str);
@ -231,6 +233,8 @@ int freerdp_client_print_command_line_help(int argc, char** argv)
{ {
length = (int) strlen(arg->Name) + 32; length = (int) strlen(arg->Name) + 32;
str = (char*) calloc(length + 1UL, sizeof(char)); str = (char*) calloc(length + 1UL, sizeof(char));
if (!str)
return -1;
sprintf_s(str, length + 1, "%s (default:%s)", arg->Name, sprintf_s(str, length + 1, "%s (default:%s)", arg->Name,
arg->Default ? "on" : "off"); arg->Default ? "on" : "off");
@ -292,7 +296,8 @@ int freerdp_client_command_line_pre_filter(void* context, int index, int argc, L
if (_stricmp(&(argv[index])[length - 4], ".rdp") == 0) if (_stricmp(&(argv[index])[length - 4], ".rdp") == 0)
{ {
settings = (rdpSettings*) context; settings = (rdpSettings*) context;
settings->ConnectionFile = _strdup(argv[index]); if (!(settings->ConnectionFile = _strdup(argv[index])))
return COMMAND_LINE_ERROR_MEMORY;
return 1; return 1;
} }
@ -303,7 +308,8 @@ int freerdp_client_command_line_pre_filter(void* context, int index, int argc, L
if (_stricmp(&(argv[index])[length - 13], ".msrcIncident") == 0) if (_stricmp(&(argv[index])[length - 13], ".msrcIncident") == 0)
{ {
settings = (rdpSettings*) context; settings = (rdpSettings*) context;
settings->AssistanceFile = _strdup(argv[index]); if (!(settings->AssistanceFile = _strdup(argv[index])))
return COMMAND_LINE_ERROR_MEMORY;
return 1; return 1;
} }
@ -332,12 +338,31 @@ int freerdp_client_add_device_channel(rdpSettings* settings, int count, char** p
drive->Type = RDPDR_DTYP_FILESYSTEM; drive->Type = RDPDR_DTYP_FILESYSTEM;
if (count > 1) if (count > 1)
drive->Name = _strdup(params[1]); {
if (!(drive->Name = _strdup(params[1])))
{
free(drive);
return -1;
}
}
if (count > 2) if (count > 2)
drive->Path = _strdup(params[2]); {
if (!(drive->Path = _strdup(params[2])))
{
free(drive->Name);
free(drive);
return -1;
}
}
freerdp_device_collection_add(settings, (RDPDR_DEVICE*) drive); if (!freerdp_device_collection_add(settings, (RDPDR_DEVICE*) drive))
{
free(drive->Path);
free(drive->Name);
free(drive);
return -1;
}
return 1; return 1;
} }
@ -361,12 +386,33 @@ int freerdp_client_add_device_channel(rdpSettings* settings, int count, char** p
printer->Type = RDPDR_DTYP_PRINT; printer->Type = RDPDR_DTYP_PRINT;
if (count > 1) if (count > 1)
printer->Name = _strdup(params[1]); {
if (!(printer->Name = _strdup(params[1])))
{
free(printer);
return -1;
}
}
if (count > 2) if (count > 2)
printer->DriverName = _strdup(params[2]); {
if (!(printer->DriverName = _strdup(params[2])))
{
free(printer->Name);
free(printer);
return -1;
}
}
if (!freerdp_device_collection_add(settings, (RDPDR_DEVICE*) printer))
{
free(printer->DriverName);
free(printer->Name);
free(printer);
return -1;
}
freerdp_device_collection_add(settings, (RDPDR_DEVICE*) printer);
} }
return 1; return 1;
@ -391,12 +437,30 @@ int freerdp_client_add_device_channel(rdpSettings* settings, int count, char** p
smartcard->Type = RDPDR_DTYP_SMARTCARD; smartcard->Type = RDPDR_DTYP_SMARTCARD;
if (count > 1) if (count > 1)
smartcard->Name = _strdup(params[1]); {
if (!(smartcard->Name = _strdup(params[1])))
{
free(smartcard);
return -1;
}
}
if (count > 2) if (count > 2)
smartcard->Path = _strdup(params[2]); {
if (!(smartcard->Path = _strdup(params[2])))
freerdp_device_collection_add(settings, (RDPDR_DEVICE*) smartcard); {
free(smartcard->Name);
free(smartcard);
return -1;
}
}
if (!freerdp_device_collection_add(settings, (RDPDR_DEVICE*) smartcard))
{
free(smartcard->Path);
free(smartcard->Name);
free(smartcard);
return -1;
}
} }
return 1; return 1;
@ -419,18 +483,56 @@ int freerdp_client_add_device_channel(rdpSettings* settings, int count, char** p
serial->Type = RDPDR_DTYP_SERIAL; serial->Type = RDPDR_DTYP_SERIAL;
if (count > 1) if (count > 1)
serial->Name = _strdup(params[1]); {
if (!(serial->Name = _strdup(params[1])))
{
free(serial);
return -1;
}
}
if (count > 2) if (count > 2)
serial->Path = _strdup(params[2]); {
if (!(serial->Path = _strdup(params[2])))
{
free(serial->Name);
free(serial);
return -1;
}
}
if (count > 3) if (count > 3)
serial->Driver = _strdup(params[3]); {
if (!(serial->Driver = _strdup(params[3])))
{
free(serial->Path);
free(serial->Name);
free(serial);
return -1;
}
}
if (count > 4) if (count > 4)
serial->Permissive = _strdup(params[4]); {
if (!(serial->Permissive = _strdup(params[4])))
{
free(serial->Driver);
free(serial->Path);
free(serial->Name);
free(serial);
return -1;
}
}
freerdp_device_collection_add(settings, (RDPDR_DEVICE*) serial); if (!freerdp_device_collection_add(settings, (RDPDR_DEVICE*) serial))
{
free(serial->Permissive);
free(serial->Driver);
free(serial->Path);
free(serial->Name);
free(serial);
return -1;
}
return 1; return 1;
} }
@ -452,12 +554,31 @@ int freerdp_client_add_device_channel(rdpSettings* settings, int count, char** p
parallel->Type = RDPDR_DTYP_PARALLEL; parallel->Type = RDPDR_DTYP_PARALLEL;
if (count > 1) if (count > 1)
parallel->Name = _strdup(params[1]); {
if (!(parallel->Name = _strdup(params[1])))
{
free(parallel);
return -1;
}
}
if (count > 2) if (count > 2)
parallel->Path = _strdup(params[2]); {
if (!(parallel->Path = _strdup(params[2])))
{
free(parallel->Name);
free(parallel);
return -1;
}
}
freerdp_device_collection_add(settings, (RDPDR_DEVICE*) parallel); if (!freerdp_device_collection_add(settings, (RDPDR_DEVICE*) parallel))
{
free(parallel->Path);
free(parallel->Name);
free(parallel);
return -1;
}
return 1; return 1;
} }
@ -470,7 +591,7 @@ int freerdp_client_add_static_channel(rdpSettings* settings, int count, char** p
int index; int index;
ADDIN_ARGV* args; ADDIN_ARGV* args;
args = (ADDIN_ARGV*) malloc(sizeof(ADDIN_ARGV)); args = (ADDIN_ARGV*) calloc(1, sizeof(ADDIN_ARGV));
if (!args) if (!args)
return -1; return -1;
@ -483,7 +604,12 @@ int freerdp_client_add_static_channel(rdpSettings* settings, int count, char** p
{ {
args->argv[index] = _strdup(params[index]); args->argv[index] = _strdup(params[index]);
if (!args->argv[index]) if (!args->argv[index])
goto error_argv_index; {
for (--index; index >= 0; --index)
free(args->argv[index]);
goto error_argv_strdup;
}
} }
if (!freerdp_static_channel_collection_add(settings, args)) if (!freerdp_static_channel_collection_add(settings, args))
@ -494,6 +620,7 @@ int freerdp_client_add_static_channel(rdpSettings* settings, int count, char** p
error_argv_index: error_argv_index:
for (index = 0; index < args->argc; index++) for (index = 0; index < args->argc; index++)
free(args->argv[index]); free(args->argv[index]);
error_argv_strdup:
free(args->argv); free(args->argv);
error_argv: error_argv:
free(args); free(args);
@ -518,7 +645,12 @@ int freerdp_client_add_dynamic_channel(rdpSettings* settings, int count, char**
{ {
args->argv[index] = _strdup(params[index]); args->argv[index] = _strdup(params[index]);
if (!args->argv[index]) if (!args->argv[index])
goto error_argv_index; {
for (--index; index >= 0; --index)
free(args->argv[index]);
goto error_argv_strdup;
}
} }
if (!freerdp_dynamic_channel_collection_add(settings, args)) if (!freerdp_dynamic_channel_collection_add(settings, args))
@ -529,6 +661,7 @@ int freerdp_client_add_dynamic_channel(rdpSettings* settings, int count, char**
error_argv_index: error_argv_index:
for (index = 0; index < args->argc; index++) for (index = 0; index < args->argc; index++)
free(args->argv[index]); free(args->argv[index]);
error_argv_strdup:
free(args->argv); free(args->argv);
error_argv: error_argv:
free(args); free(args);
@ -556,6 +689,8 @@ static char** freerdp_command_line_parse_comma_separated_values(char* list, int*
nArgs = nCommas + 1; nArgs = nCommas + 1;
p = (char**) calloc((nArgs + 1UL), sizeof(char*)); p = (char**) calloc((nArgs + 1UL), sizeof(char*));
if (!p)
return NULL;
str = (char*) list; str = (char*) list;
@ -1326,13 +1461,16 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
{ {
length = (int) (p - arg->Value); length = (int) (p - arg->Value);
settings->ServerPort = atoi(&p[1]); settings->ServerPort = atoi(&p[1]);
settings->ServerHostname = (char*) calloc(length + 1UL, sizeof(char)); if (!(settings->ServerHostname = (char*) calloc(length + 1UL, sizeof(char))))
return COMMAND_LINE_ERROR_MEMORY;
strncpy(settings->ServerHostname, arg->Value, length); strncpy(settings->ServerHostname, arg->Value, length);
settings->ServerHostname[length] = '\0'; settings->ServerHostname[length] = '\0';
} }
else else
{ {
settings->ServerHostname = _strdup(arg->Value); if (!(settings->ServerHostname = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
} }
} }
else /* ipv6 */ else /* ipv6 */
@ -1343,7 +1481,8 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
continue; continue;
length = p2 - p; length = p2 - p;
settings->ServerHostname = (char*) calloc(length, sizeof(char)); if (!(settings->ServerHostname = (char*) calloc(length, sizeof(char))))
return COMMAND_LINE_ERROR;
strncpy(settings->ServerHostname, p+1, length-1); strncpy(settings->ServerHostname, p+1, length-1);
if (*(p2 + 1) == ':') if (*(p2 + 1) == ':')
{ {
@ -1354,7 +1493,9 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
} }
CommandLineSwitchCase(arg, "spn-class") CommandLineSwitchCase(arg, "spn-class")
{ {
settings->AuthenticationServiceClass = _strdup(arg->Value); if (!(settings->AuthenticationServiceClass = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
} }
CommandLineSwitchCase(arg, "credentials-delegation") CommandLineSwitchCase(arg, "credentials-delegation")
{ {
@ -1368,7 +1509,8 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
if (arg->Flags & COMMAND_LINE_VALUE_PRESENT) if (arg->Flags & COMMAND_LINE_VALUE_PRESENT)
{ {
settings->SendPreconnectionPdu = TRUE; settings->SendPreconnectionPdu = TRUE;
settings->PreconnectionBlob = _strdup(arg->Value); if (!(settings->PreconnectionBlob = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
} }
} }
CommandLineSwitchCase(arg, "w") CommandLineSwitchCase(arg, "w")
@ -1381,7 +1523,8 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
} }
CommandLineSwitchCase(arg, "size") CommandLineSwitchCase(arg, "size")
{ {
str = _strdup(arg->Value); if (!(str = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
p = strchr(str, 'x'); p = strchr(str, 'x');
@ -1435,6 +1578,8 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
int count = 0; int count = 0;
p = freerdp_command_line_parse_comma_separated_values(arg->Value, &count); p = freerdp_command_line_parse_comma_separated_values(arg->Value, &count);
if (!p)
return COMMAND_LINE_ERROR_MEMORY;
if (count > 16) if (count > 16)
count = 16; count = 16;
@ -1455,7 +1600,8 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
} }
CommandLineSwitchCase(arg, "t") CommandLineSwitchCase(arg, "t")
{ {
settings->WindowTitle = _strdup(arg->Value); if (!(settings->WindowTitle = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
} }
CommandLineSwitchCase(arg, "decorations") CommandLineSwitchCase(arg, "decorations")
{ {
@ -1467,7 +1613,8 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
if (arg->Value) if (arg->Value)
{ {
str = _strdup(arg->Value); if (!(str = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
if ((p = strchr(str, 'x'))) if ((p = strchr(str, 'x')))
{ {
*p = '\0'; *p = '\0';
@ -1494,11 +1641,13 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
{ {
settings->ConsoleSession = TRUE; settings->ConsoleSession = TRUE;
settings->RestrictedAdminModeRequired = TRUE; settings->RestrictedAdminModeRequired = TRUE;
settings->PasswordHash = _strdup(arg->Value); if (!(settings->PasswordHash = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
} }
CommandLineSwitchCase(arg, "client-hostname") CommandLineSwitchCase(arg, "client-hostname")
{ {
settings->ClientHostname = _strdup(arg->Value); if (!(settings->ClientHostname = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
} }
CommandLineSwitchCase(arg, "kbd") CommandLineSwitchCase(arg, "kbd")
{ {
@ -1544,11 +1693,13 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
} }
CommandLineSwitchCase(arg, "d") CommandLineSwitchCase(arg, "d")
{ {
settings->Domain = _strdup(arg->Value); if (!(settings->Domain = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
} }
CommandLineSwitchCase(arg, "p") CommandLineSwitchCase(arg, "p")
{ {
settings->Password = _strdup(arg->Value); if (!(settings->Password = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
} }
CommandLineSwitchCase(arg, "g") CommandLineSwitchCase(arg, "g")
{ {
@ -1560,18 +1711,21 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
{ {
length = (int) (p - arg->Value); length = (int) (p - arg->Value);
settings->GatewayPort = atoi(&p[1]); settings->GatewayPort = atoi(&p[1]);
settings->GatewayHostname = (char*) calloc(length + 1UL, sizeof(char)); if (!(settings->GatewayHostname = (char*) calloc(length + 1UL, sizeof(char))))
return COMMAND_LINE_ERROR_MEMORY;
strncpy(settings->GatewayHostname, arg->Value, length); strncpy(settings->GatewayHostname, arg->Value, length);
settings->GatewayHostname[length] = '\0'; settings->GatewayHostname[length] = '\0';
} }
else else
{ {
settings->GatewayHostname = _strdup(arg->Value); if (!(settings->GatewayHostname = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
} }
} }
else else
{ {
settings->GatewayHostname = _strdup(settings->ServerHostname); if (!(settings->GatewayHostname = _strdup(settings->ServerHostname)))
return COMMAND_LINE_ERROR_MEMORY;
} }
settings->GatewayEnabled = TRUE; settings->GatewayEnabled = TRUE;
@ -1581,17 +1735,21 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
} }
CommandLineSwitchCase(arg, "gu") CommandLineSwitchCase(arg, "gu")
{ {
gwUser = _strdup(arg->Value); if (!(gwUser = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
settings->GatewayUseSameCredentials = FALSE; settings->GatewayUseSameCredentials = FALSE;
} }
CommandLineSwitchCase(arg, "gd") CommandLineSwitchCase(arg, "gd")
{ {
settings->GatewayDomain = _strdup(arg->Value); if (!(settings->GatewayDomain = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
settings->GatewayUseSameCredentials = FALSE; settings->GatewayUseSameCredentials = FALSE;
} }
CommandLineSwitchCase(arg, "gp") CommandLineSwitchCase(arg, "gp")
{ {
settings->GatewayPassword = _strdup(arg->Value); if (!(settings->GatewayPassword = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
settings->GatewayUseSameCredentials = FALSE; settings->GatewayUseSameCredentials = FALSE;
} }
CommandLineSwitchCase(arg, "gt") CommandLineSwitchCase(arg, "gt")
@ -1635,7 +1793,8 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
} }
CommandLineSwitchCase(arg, "app") CommandLineSwitchCase(arg, "app")
{ {
settings->RemoteApplicationProgram = _strdup(arg->Value); if (!(settings->RemoteApplicationProgram = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
settings->RemoteApplicationMode = TRUE; settings->RemoteApplicationMode = TRUE;
settings->RemoteAppLanguageBarSupported = TRUE; settings->RemoteAppLanguageBarSupported = TRUE;
@ -1645,28 +1804,35 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
} }
CommandLineSwitchCase(arg, "load-balance-info") CommandLineSwitchCase(arg, "load-balance-info")
{ {
settings->LoadBalanceInfo = (BYTE*) _strdup(arg->Value); if (!(settings->LoadBalanceInfo = (BYTE*) _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
settings->LoadBalanceInfoLength = (UINT32) strlen((char*) settings->LoadBalanceInfo); settings->LoadBalanceInfoLength = (UINT32) strlen((char*) settings->LoadBalanceInfo);
} }
CommandLineSwitchCase(arg, "app-name") CommandLineSwitchCase(arg, "app-name")
{ {
settings->RemoteApplicationName = _strdup(arg->Value); if (!(settings->RemoteApplicationName = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
} }
CommandLineSwitchCase(arg, "app-icon") CommandLineSwitchCase(arg, "app-icon")
{ {
settings->RemoteApplicationIcon = _strdup(arg->Value); if (!(settings->RemoteApplicationIcon = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
} }
CommandLineSwitchCase(arg, "app-cmd") CommandLineSwitchCase(arg, "app-cmd")
{ {
settings->RemoteApplicationCmdLine = _strdup(arg->Value); if (!(settings->RemoteApplicationCmdLine = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
} }
CommandLineSwitchCase(arg, "app-file") CommandLineSwitchCase(arg, "app-file")
{ {
settings->RemoteApplicationFile = _strdup(arg->Value); if (!(settings->RemoteApplicationFile = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
} }
CommandLineSwitchCase(arg, "app-guid") CommandLineSwitchCase(arg, "app-guid")
{ {
settings->RemoteApplicationGuid = _strdup(arg->Value); if (!(settings->RemoteApplicationGuid = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
} }
CommandLineSwitchCase(arg, "compression") CommandLineSwitchCase(arg, "compression")
{ {
@ -1690,11 +1856,13 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
} }
CommandLineSwitchCase(arg, "shell") CommandLineSwitchCase(arg, "shell")
{ {
settings->AlternateShell = _strdup(arg->Value); if (!(settings->AlternateShell = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
} }
CommandLineSwitchCase(arg, "shell-dir") CommandLineSwitchCase(arg, "shell-dir")
{ {
settings->ShellWorkingDirectory = _strdup(arg->Value); if (!(settings->ShellWorkingDirectory = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
} }
CommandLineSwitchCase(arg, "audio-mode") CommandLineSwitchCase(arg, "audio-mode")
{ {
@ -1846,7 +2014,8 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
CommandLineSwitchCase(arg, "pcb") CommandLineSwitchCase(arg, "pcb")
{ {
settings->SendPreconnectionPdu = TRUE; settings->SendPreconnectionPdu = TRUE;
settings->PreconnectionBlob = _strdup(arg->Value); if (!(settings->PreconnectionBlob = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
} }
CommandLineSwitchCase(arg, "pcid") CommandLineSwitchCase(arg, "pcid")
{ {
@ -1936,20 +2105,24 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
{ {
if (strcmp(arg->Value, "netmon") == 0) if (strcmp(arg->Value, "netmon") == 0)
{ {
settings->AllowedTlsCiphers = _strdup("ALL:!ECDH"); if (!(settings->AllowedTlsCiphers = _strdup("ALL:!ECDH")))
return COMMAND_LINE_ERROR_MEMORY;
} }
else if (strcmp(arg->Value, "ma") == 0) else if (strcmp(arg->Value, "ma") == 0)
{ {
settings->AllowedTlsCiphers = _strdup("AES128-SHA"); if (!(settings->AllowedTlsCiphers = _strdup("AES128-SHA")))
return COMMAND_LINE_ERROR_MEMORY;
} }
else else
{ {
settings->AllowedTlsCiphers = _strdup(arg->Value); if (!(settings->AllowedTlsCiphers = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
} }
} }
CommandLineSwitchCase(arg, "cert-name") CommandLineSwitchCase(arg, "cert-name")
{ {
settings->CertificateName = _strdup(arg->Value); if (!(settings->CertificateName = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
} }
CommandLineSwitchCase(arg, "cert-ignore") CommandLineSwitchCase(arg, "cert-ignore")
{ {
@ -2038,11 +2211,13 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
} }
CommandLineSwitchCase(arg, "wm-class") CommandLineSwitchCase(arg, "wm-class")
{ {
settings->WmClass = _strdup(arg->Value); if (!(settings->WmClass = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
} }
CommandLineSwitchCase(arg, "play-rfx") CommandLineSwitchCase(arg, "play-rfx")
{ {
settings->PlayRemoteFxFile = _strdup(arg->Value); if (!(settings->PlayRemoteFxFile = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
settings->PlayRemoteFx = TRUE; settings->PlayRemoteFx = TRUE;
} }
CommandLineSwitchCase(arg, "auth-only") CommandLineSwitchCase(arg, "auth-only")
@ -2076,7 +2251,8 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
CommandLineSwitchCase(arg, "assistance") CommandLineSwitchCase(arg, "assistance")
{ {
settings->RemoteAssistanceMode = TRUE; settings->RemoteAssistanceMode = TRUE;
settings->RemoteAssistancePassword = _strdup(arg->Value); if (!(settings->RemoteAssistancePassword = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
} }
CommandLineSwitchDefault(arg) CommandLineSwitchDefault(arg)
{ {

View File

@ -89,7 +89,7 @@ COMMAND_LINE_ARGUMENT_A old_args[] =
{ NULL, 0, NULL, NULL, NULL, -1, NULL, NULL } { NULL, 0, NULL, NULL, NULL, -1, NULL, NULL }
}; };
void freerdp_client_old_parse_hostname(char* str, char** ServerHostname, UINT32* ServerPort) BOOL freerdp_client_old_parse_hostname(char* str, char** ServerHostname, UINT32* ServerPort)
{ {
char* p; char* p;
@ -97,7 +97,8 @@ void freerdp_client_old_parse_hostname(char* str, char** ServerHostname, UINT32*
&& (p[1] == 0 || (p[1] == ':' && !strchr(p + 2, ':')))) && (p[1] == 0 || (p[1] == ':' && !strchr(p + 2, ':'))))
{ {
/* Either "[...]" or "[...]:..." with at most one : after the brackets */ /* Either "[...]" or "[...]:..." with at most one : after the brackets */
*ServerHostname = _strdup(str + 1); if (!(*ServerHostname = _strdup(str + 1)))
return FALSE;
if ((p = strchr((char*) *ServerHostname, ']'))) if ((p = strchr((char*) *ServerHostname, ']')))
{ {
@ -110,7 +111,8 @@ void freerdp_client_old_parse_hostname(char* str, char** ServerHostname, UINT32*
else else
{ {
/* Port number is cut off and used if exactly one : in the string */ /* Port number is cut off and used if exactly one : in the string */
*ServerHostname = _strdup(str); if (!(*ServerHostname = _strdup(str)))
return FALSE;
if ((p = strchr((char*) *ServerHostname, ':')) && !strchr(p + 1, ':')) if ((p = strchr((char*) *ServerHostname, ':')) && !strchr(p + 1, ':'))
{ {
@ -118,6 +120,7 @@ void freerdp_client_old_parse_hostname(char* str, char** ServerHostname, UINT32*
*ServerPort = atoi(p + 1); *ServerPort = atoi(p + 1);
} }
} }
return TRUE;
} }
int freerdp_client_old_process_plugin(rdpSettings* settings, ADDIN_ARGV* args) int freerdp_client_old_process_plugin(rdpSettings* settings, ADDIN_ARGV* args)
@ -183,7 +186,8 @@ int freerdp_client_old_process_plugin(rdpSettings* settings, ADDIN_ARGV* args)
return 1; return 1;
args_handled++; args_handled++;
settings->RemoteApplicationProgram = _strdup(args->argv[1]); if (!(settings->RemoteApplicationProgram = _strdup(args->argv[1])))
return -1;
} }
else else
{ {
@ -211,8 +215,9 @@ int freerdp_client_old_command_line_pre_filter(void* context, int index, int arg
return -1; return -1;
} }
freerdp_client_old_parse_hostname((char*) argv[index], if (!freerdp_client_old_parse_hostname((char*) argv[index],
&settings->ServerHostname, &settings->ServerPort); &settings->ServerHostname, &settings->ServerPort))
return -1;
return 2; return 2;
} }
@ -240,7 +245,14 @@ int freerdp_client_old_command_line_pre_filter(void* context, int index, int arg
return -1; return -1;
args = (ADDIN_ARGV*) malloc(sizeof(ADDIN_ARGV)); args = (ADDIN_ARGV*) malloc(sizeof(ADDIN_ARGV));
if (!args)
return -1;
args->argv = (char**) calloc(argc, sizeof(char*)); args->argv = (char**) calloc(argc, sizeof(char*));
if (!args->argv)
{
free(args);
return -1;
}
args->argc = 1; args->argc = 1;
if ((index < argc - 1) && strcmp("--data", argv[index + 1]) == 0) if ((index < argc - 1) && strcmp("--data", argv[index + 1]) == 0)
@ -250,9 +262,14 @@ int freerdp_client_old_command_line_pre_filter(void* context, int index, int arg
while ((index < argc) && (strcmp("--", argv[index]) != 0)) while ((index < argc) && (strcmp("--", argv[index]) != 0))
{ {
args_handled ++; args_handled++;
args->argc = 1; args->argc = 1;
args->argv[0] = _strdup(argv[t]); if (!(args->argv[0] = _strdup(argv[t])))
{
free(args->argv);
free(args);
return -1;
}
for (j = 0, p = (char*) argv[index]; (j < 4) && (p != NULL); j++) for (j = 0, p = (char*) argv[index]; (j < 4) && (p != NULL); j++)
{ {
@ -277,14 +294,31 @@ int freerdp_client_old_command_line_pre_filter(void* context, int index, int arg
if (p != NULL) if (p != NULL)
{ {
length = (int) (p - a); length = (int) (p - a);
args->argv[j + 1] = (char*) malloc(length + 1); if (!(args->argv[j + 1] = (char*) malloc(length + 1)))
{
for (; j >= 0; --j)
free(args->argv[j]);
free(args->argv);
free(args);
return -1;
}
CopyMemory(args->argv[j + 1], a, length); CopyMemory(args->argv[j + 1], a, length);
args->argv[j + 1][length] = '\0'; args->argv[j + 1][length] = '\0';
p++; p++;
} }
else else
{ {
args->argv[j + 1] = _strdup(a); if (!(args->argv[j + 1] = _strdup(a)))
{
for (; j >= 0; --j)
free(args->argv[j]);
free(args->argv);
free(args);
return -1;
}
} }
args->argc++; args->argc++;
@ -306,7 +340,12 @@ int freerdp_client_old_command_line_pre_filter(void* context, int index, int arg
{ {
if (settings) if (settings)
{ {
args->argv[0] = _strdup(argv[t]); if (!(args->argv[0] = _strdup(argv[t])))
{
free(args->argv);
free(args);
return -1;
}
args_handled = freerdp_client_old_process_plugin(settings, args); args_handled = freerdp_client_old_process_plugin(settings, args);
free (args->argv[0]); free (args->argv[0]);
} }
@ -459,8 +498,9 @@ int freerdp_client_parse_old_command_line_arguments(int argc, char** argv, rdpSe
} }
CommandLineSwitchCase(arg, "c") CommandLineSwitchCase(arg, "c")
{ {
settings->ShellWorkingDirectory = _strdup(arg->Value);
WLog_WARN(TAG, "-c %s -> /shell-dir:%s", arg->Value, arg->Value); WLog_WARN(TAG, "-c %s -> /shell-dir:%s", arg->Value, arg->Value);
if (!(settings->ShellWorkingDirectory = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
} }
CommandLineSwitchCase(arg, "D") CommandLineSwitchCase(arg, "D")
{ {
@ -469,12 +509,14 @@ int freerdp_client_parse_old_command_line_arguments(int argc, char** argv, rdpSe
} }
CommandLineSwitchCase(arg, "T") CommandLineSwitchCase(arg, "T")
{ {
settings->WindowTitle = _strdup(arg->Value); if (!(settings->WindowTitle = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
WLog_WARN(TAG, "-T %s -> /title:%s", arg->Value, arg->Value); WLog_WARN(TAG, "-T %s -> /title:%s", arg->Value, arg->Value);
} }
CommandLineSwitchCase(arg, "d") CommandLineSwitchCase(arg, "d")
{ {
settings->Domain = _strdup(arg->Value); if (!(settings->Domain = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
WLog_WARN(TAG, "-d %s -> /d:%s", arg->Value, arg->Value); WLog_WARN(TAG, "-d %s -> /d:%s", arg->Value, arg->Value);
} }
CommandLineSwitchCase(arg, "f") CommandLineSwitchCase(arg, "f")
@ -484,7 +526,8 @@ int freerdp_client_parse_old_command_line_arguments(int argc, char** argv, rdpSe
} }
CommandLineSwitchCase(arg, "g") CommandLineSwitchCase(arg, "g")
{ {
str = _strdup(arg->Value); if (!(str = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
p = strchr(str, 'x'); p = strchr(str, 'x');
@ -511,7 +554,8 @@ int freerdp_client_parse_old_command_line_arguments(int argc, char** argv, rdpSe
} }
CommandLineSwitchCase(arg, "n") CommandLineSwitchCase(arg, "n")
{ {
settings->ClientHostname = _strdup(arg->Value); if (!(settings->ClientHostname = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
WLog_WARN(TAG, "-n -> /client-hostname:%s", arg->Value); WLog_WARN(TAG, "-n -> /client-hostname:%s", arg->Value);
} }
CommandLineSwitchCase(arg, "o") CommandLineSwitchCase(arg, "o")
@ -521,14 +565,16 @@ int freerdp_client_parse_old_command_line_arguments(int argc, char** argv, rdpSe
} }
CommandLineSwitchCase(arg, "p") CommandLineSwitchCase(arg, "p")
{ {
settings->Password = _strdup(arg->Value); if (!(settings->Password = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
WLog_WARN(TAG, "-p ****** -> /p:******"); WLog_WARN(TAG, "-p ****** -> /p:******");
/* Hide the value from 'ps'. */ /* Hide the value from 'ps'. */
FillMemory(arg->Value, strlen(arg->Value), '*'); FillMemory(arg->Value, strlen(arg->Value), '*');
} }
CommandLineSwitchCase(arg, "s") CommandLineSwitchCase(arg, "s")
{ {
settings->AlternateShell = _strdup(arg->Value); if (!(settings->AlternateShell = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
WLog_WARN(TAG, "-s %s -> /shell:%s", arg->Value, arg->Value); WLog_WARN(TAG, "-s %s -> /shell:%s", arg->Value, arg->Value);
} }
CommandLineSwitchCase(arg, "t") CommandLineSwitchCase(arg, "t")
@ -538,7 +584,8 @@ int freerdp_client_parse_old_command_line_arguments(int argc, char** argv, rdpSe
} }
CommandLineSwitchCase(arg, "u") CommandLineSwitchCase(arg, "u")
{ {
settings->Username = _strdup(arg->Value); if (!(settings->Username = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
WLog_WARN(TAG, "-u %s -> /u:%s", arg->Value, arg->Value); WLog_WARN(TAG, "-u %s -> /u:%s", arg->Value, arg->Value);
} }
CommandLineSwitchCase(arg, "x") CommandLineSwitchCase(arg, "x")

View File

@ -1435,7 +1435,7 @@ FREERDP_API int freerdp_addin_replace_argument(ADDIN_ARGV* args, char* previous,
FREERDP_API int freerdp_addin_set_argument_value(ADDIN_ARGV* args, char* option, char* value); FREERDP_API int freerdp_addin_set_argument_value(ADDIN_ARGV* args, char* option, char* value);
FREERDP_API int freerdp_addin_replace_argument_value(ADDIN_ARGV* args, char* previous, char* option, char* value); FREERDP_API int freerdp_addin_replace_argument_value(ADDIN_ARGV* args, char* previous, char* option, char* value);
FREERDP_API void freerdp_device_collection_add(rdpSettings* settings, RDPDR_DEVICE* device); FREERDP_API BOOL freerdp_device_collection_add(rdpSettings* settings, RDPDR_DEVICE* device);
FREERDP_API RDPDR_DEVICE* freerdp_device_collection_find(rdpSettings* settings, const char* name); FREERDP_API RDPDR_DEVICE* freerdp_device_collection_find(rdpSettings* settings, const char* name);
FREERDP_API RDPDR_DEVICE* freerdp_device_clone(RDPDR_DEVICE* device); FREERDP_API RDPDR_DEVICE* freerdp_device_clone(RDPDR_DEVICE* device);
FREERDP_API void freerdp_device_collection_free(rdpSettings* settings); FREERDP_API void freerdp_device_collection_free(rdpSettings* settings);

View File

@ -159,10 +159,10 @@ int freerdp_addin_replace_argument_value(ADDIN_ARGV* args, char* previous, char*
return 0; return 0;
} }
void freerdp_device_collection_add(rdpSettings* settings, RDPDR_DEVICE* device) BOOL freerdp_device_collection_add(rdpSettings* settings, RDPDR_DEVICE* device)
{ {
if (!settings->DeviceArray) if (!settings->DeviceArray)
return; return FALSE;
if (settings->DeviceArraySize < (settings->DeviceCount + 1)) if (settings->DeviceArraySize < (settings->DeviceCount + 1))
{ {
@ -173,12 +173,13 @@ void freerdp_device_collection_add(rdpSettings* settings, RDPDR_DEVICE* device)
new_array = (RDPDR_DEVICE**) new_array = (RDPDR_DEVICE**)
realloc(settings->DeviceArray, new_size * sizeof(RDPDR_DEVICE*)); realloc(settings->DeviceArray, new_size * sizeof(RDPDR_DEVICE*));
if (!new_array) if (!new_array)
return; return FALSE;
settings->DeviceArray = new_array; settings->DeviceArray = new_array;
settings->DeviceArraySize = new_size; settings->DeviceArraySize = new_size;
} }
settings->DeviceArray[settings->DeviceCount++] = device; settings->DeviceArray[settings->DeviceCount++] = device;
return TRUE;
} }
RDPDR_DEVICE* freerdp_device_collection_find(rdpSettings* settings, const char* name) RDPDR_DEVICE* freerdp_device_collection_find(rdpSettings* settings, const char* name)

View File

@ -64,13 +64,14 @@
/* Command-Line Parsing Error Codes */ /* Command-Line Parsing Error Codes */
#define COMMAND_LINE_ERROR -1000 #define COMMAND_LINE_ERROR -1000
#define COMMAND_LINE_ERROR_NO_KEYWORD -1001 #define COMMAND_LINE_ERROR_NO_KEYWORD -1001
#define COMMAND_LINE_ERROR_UNEXPECTED_VALUE -1002 #define COMMAND_LINE_ERROR_UNEXPECTED_VALUE -1002
#define COMMAND_LINE_ERROR_MISSING_VALUE -1003 #define COMMAND_LINE_ERROR_MISSING_VALUE -1003
#define COMMAND_LINE_ERROR_MISSING_ARGUMENT -1004 #define COMMAND_LINE_ERROR_MISSING_ARGUMENT -1004
#define COMMAND_LINE_ERROR_UNEXPECTED_SIGIL -1005 #define COMMAND_LINE_ERROR_UNEXPECTED_SIGIL -1005
#define COMMAND_LINE_ERROR_LAST -1006 #define COMMAND_LINE_ERROR_MEMORY -1006
#define COMMAND_LINE_ERROR_LAST -1999
/* Command-Line Parsing Status Codes */ /* Command-Line Parsing Status Codes */