diff --git a/src/config.c b/src/config.c index 7bd49057..b306ee46 100644 --- a/src/config.c +++ b/src/config.c @@ -1560,6 +1560,7 @@ static int ssh_config_parse_line_internal(ssh_session session, break; } switch (*endp) { + case 'g': case 'G': if (ll > LLONG_MAX / 1024) { SSH_LOG(SSH_LOG_TRACE, "Possible overflow of rekey limit"); @@ -1568,6 +1569,7 @@ static int ssh_config_parse_line_internal(ssh_session session, } ll = ll * 1024; FALL_THROUGH; + case 'm': case 'M': if (ll > LLONG_MAX / 1024) { SSH_LOG(SSH_LOG_TRACE, "Possible overflow of rekey limit"); @@ -1576,6 +1578,7 @@ static int ssh_config_parse_line_internal(ssh_session session, } ll = ll * 1024; FALL_THROUGH; + case 'k': case 'K': if (ll > LLONG_MAX / 1024) { SSH_LOG(SSH_LOG_TRACE, "Possible overflow of rekey limit"); @@ -1589,12 +1592,8 @@ static int ssh_config_parse_line_internal(ssh_session session, /* just the number */ break; default: - /* Invalid suffix */ - ll = -1; - break; - } - if (*endp != ' ' && *endp != '\0') { - CHECK_COND_OR_FAIL(1, "Invalid trailing characters"); + /* Ignore invalid suffix and trailing garbage */ + SSH_LOG(SSH_LOG_TRACE, "Ignoring invalid suffix"); break; } } @@ -1663,12 +1662,8 @@ static int ssh_config_parse_line_internal(ssh_session session, /* just the number */ break; default: - /* Invalid suffix */ - ll = -1; - break; - } - if (*endp != '\0') { - CHECK_COND_OR_FAIL(1, "Invalid trailing characters"); + /* Ignore invalid suffix and trailing garbage */ + SSH_LOG(SSH_LOG_TRACE, "Ignoring invalid suffix"); break; } } diff --git a/tests/unittests/torture_config.c b/tests/unittests/torture_config.c index d54549a5..fd8683a9 100644 --- a/tests/unittests/torture_config.c +++ b/tests/unittests/torture_config.c @@ -183,6 +183,8 @@ extern LIBSSH_THREAD int ssh_log_level; "\tRekeyLimit 31M\n" \ "Host data3\n" \ "\tRekeyLimit 521K\n" \ + "Host data4\n" \ + "\tRekeyLimit 5k*n\n" \ "Host time1\n" \ "\tRekeyLimit default 3D\n" \ "Host time2\n" \ @@ -2106,6 +2108,13 @@ static void torture_config_rekey(void **state, assert_int_equal(session->opts.rekey_data, 521 * 1024); assert_int_equal(session->opts.rekey_time, 0); + /* 5k*n -> 5120 (Invalid suffix is ignored) */ + torture_reset_config(session); + ssh_options_set(session, SSH_OPTIONS_HOST, "data4"); + _parse_config(session, file, string, SSH_OK); + assert_int_equal(session->opts.rekey_data, 5 * 1024); + assert_int_equal(session->opts.rekey_time, 0); + /* default 3D */ torture_reset_config(session); ssh_options_set(session, SSH_OPTIONS_HOST, "time1");