dovecot-2.2: lib: test-strnum - do not invite undetectable errors
dovecot at dovecot.org
dovecot at dovecot.org
Tue Sep 8 16:30:15 UTC 2015
details: http://hg.dovecot.org/dovecot-2.2/rev/8687e24d9019
changeset: 19139:8687e24d9019
user: Phil Carmody <phil at dovecot.fi>
date: Tue Sep 08 19:28:31 2015 +0300
description:
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 <phil at dovecot.fi>
diffstat:
src/lib/test-strnum.c | 16 +++++++++-------
1 files changed, 9 insertions(+), 7 deletions(-)
diffs (64 lines):
diff -r 11e13b7df9f6 -r 8687e24d9019 src/lib/test-strnum.c
--- a/src/lib/test-strnum.c Tue Sep 08 19:12:26 2015 +0300
+++ b/src/lib/test-strnum.c Tue Sep 08 19:28:31 2015 +0300
@@ -28,7 +28,7 @@
{
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 @@
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 @@
{
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 @@
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 @@
{
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 @@
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();
}
More information about the dovecot-cvs
mailing list