Fix Do string argument checks before a possible strtol
strtol sets errno, which must be reset if it is no abort condition.
Invert the comparisons to avoid that.
@@ -1965,15 +1965,9 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
}
CommandLineSwitchCase(arg, "gateway-usage-method")
{
- long type;
+ long type = 0;
char* pEnd;
- type = strtol(arg->Value, &pEnd, 10);
-
- if (errno != 0)
- return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
- if (type == 0)
- {
if (_stricmp(arg->Value, "none") == 0)
type = TSC_PROXY_MODE_NONE_DIRECT;
else if (_stricmp(arg->Value, "direct") == 0)
@@ -1982,6 +1976,11 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
type = TSC_PROXY_MODE_DETECT;
else if (_stricmp(arg->Value, "default") == 0)
type = TSC_PROXY_MODE_DEFAULT;
+ else
+ {
+ type = strtol(arg->Value, &pEnd, 10);
+ if (errno != 0)
+ return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
}
freerdp_set_gateway_usage_method(settings, (UINT32) type);
@@ -2110,15 +2109,9 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
}
CommandLineSwitchCase(arg, "network")
{
- long type;
+ long type = 0;
char* pEnd;
- type = strtol(arg->Value, &pEnd, 10);
- if (errno != 0)
- return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
-
- if (type == 0)
- {
if (_stricmp(arg->Value, "modem") == 0)
type = CONNECTION_TYPE_MODEM;
else if (_stricmp(arg->Value, "broadband") == 0)
@@ -2137,6 +2130,12 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
{
type = CONNECTION_TYPE_AUTODETECT;
}
+ else
+ {
+ type = strtol(arg->Value, &pEnd, 10);
+
+ if (errno != 0)
+ return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
}
if (!freerdp_set_connection_type(settings, type))
