From: Phil Carmody Date: Tue, 8 Sep 2015 16:28:31 +0000 (+0300) Subject: lib: test-strnum - do not invite undetectable errors X-Git-Tag: 2.2.19.rc1~55 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d6bbf85809664a810726b5c711c7213874d8df57;p=thirdparty%2Fdovecot%2Fcore.git lib: test-strnum - do not invite undetectable errors The very numbers which could cause a broken parser to over-run, the ones we are testing, are the ones which will be parsed as having a value similar to 'value', so check that no value was returned by using a number completely dissimilar to that. Otherwise, there might be an accidental mis-parse that overwrote value, but left its value the same. Signed-off-by: Phil Carmody --- diff --git a/src/lib/test-strnum.c b/src/lib/test-strnum.c index c4a9e69c12..2437c6591f 100644 --- a/src/lib/test-strnum.c +++ b/src/lib/test-strnum.c @@ -28,7 +28,7 @@ static void test_str_to_uintmax(void) { unsigned int i=0; int randrange = rand()%15+1; /* when 1, will max out on 1s */ - uintmax_t value = 0; + uintmax_t value = 0, valbase = rand() * 1000ull; int len, ret; char buff[50]; /* totally assumes < 159 bits */ @@ -73,9 +73,9 @@ static void test_str_to_uintmax(void) while (buff[--j] == '9') buff[j] = '0'; buff[j]++; - + value = valbase + i; ret = str_to_uintmax(buff, &value); - test_assert_idx(ret < 0 && value == UINTMAX_MAX/9-1, i); + test_assert_idx(ret < 0 && value == valbase + i, i); } test_end(); } @@ -101,7 +101,7 @@ static void test_str_to_uintmax_hex(void) { unsigned int i=0; int randrange = rand()%15+1; /* when 1, will max out on 1s */ - uintmax_t value = 0; + uintmax_t value = 0, valbase = rand() * 1000ull; int len, ret; char buff[52]; /* totally assumes < 200 bits */ @@ -149,8 +149,9 @@ static void test_str_to_uintmax_hex(void) buff[j] = 'a'; else buff[j]++; + value = valbase + i; ret = str_to_uintmax_hex(buff, &value); - test_assert_idx(ret < 0 && value == UINTMAX_MAX/0x0f-1, i); + test_assert_idx(ret < 0 && value == valbase + i, i); } test_end(); } @@ -176,7 +177,7 @@ static void test_str_to_uintmax_oct(void) { unsigned int i=0; int randrange = rand()%15+1; /* when 1, will max out on 1s */ - uintmax_t value = 0; + uintmax_t value = 0, valbase = rand() * 1000ull; int len, ret; char buff[69]; /* totally assumes < 200 bits */ @@ -221,8 +222,9 @@ static void test_str_to_uintmax_oct(void) while (buff[--j] == '7') buff[j] = '0'; buff[j]++; + value = valbase + i; ret = str_to_uintmax_oct(buff, &value); - test_assert_idx(ret < 0 && value == UINTMAX_MAX/007-1, i); + test_assert_idx(ret < 0 && value == valbase + i, i); } test_end(); }