From: Yu Watanabe Date: Tue, 23 Oct 2018 13:25:01 +0000 (+0900) Subject: test: add tests for detecting overflow in parse_time() and parse_nsec() X-Git-Tag: v240~491^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=db4e61071d8f1cdf5f2f0c75985a65036cac2373;p=thirdparty%2Fsystemd.git test: add tests for detecting overflow in parse_time() and parse_nsec() --- diff --git a/src/test/test-time-util.c b/src/test/test-time-util.c index 58c365df573..82a71d04788 100644 --- a/src/test/test-time-util.c +++ b/src/test/test-time-util.c @@ -94,6 +94,9 @@ static void test_parse_time(void) { assert_se(parse_time("5s", &u, USEC_PER_MSEC) >= 0); assert_se(u == 5 * USEC_PER_SEC); + + assert_se(parse_time("11111111111111y", &u, 1) == -ERANGE); + assert_se(parse_time("1.1111111111111y", &u, 1) == -ERANGE); } static void test_parse_nsec(void) { @@ -144,6 +147,8 @@ static void test_parse_nsec(void) { assert_se(parse_nsec("3.+1s", &u) < 0); assert_se(parse_nsec("3. 1s", &u) < 0); assert_se(parse_nsec("3.s", &u) < 0); + assert_se(parse_nsec("1111111111111y", &u) == -ERANGE); + assert_se(parse_nsec("1.111111111111y", &u) == -ERANGE); } static void test_format_timespan_one(usec_t x, usec_t accuracy) {