diff options
author | Nick Mathewson <nickm@torproject.org> | 2017-09-12 17:09:47 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2017-09-12 17:09:47 -0400 |
commit | 3092c8bb3e5eef94016327a83b07bab1c4ab3694 (patch) | |
tree | 2dec95c461fd561d2cdc854c711092a1d6a5d515 /src/test/test_util.c | |
parent | 9c27f56cd9537d46c8d3acebf3ef37ff43b5c03b (diff) | |
parent | eb078a3bd5bc645177600aff7cbbe59d6e25c3a4 (diff) | |
download | tor-3092c8bb3e5eef94016327a83b07bab1c4ab3694.tar.gz tor-3092c8bb3e5eef94016327a83b07bab1c4ab3694.zip |
Merge branch 'maint-0.3.1'
Diffstat (limited to 'src/test/test_util.c')
-rw-r--r-- | src/test/test_util.c | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/test/test_util.c b/src/test/test_util.c index b7818202c3..6e54c8bf52 100644 --- a/src/test/test_util.c +++ b/src/test/test_util.c @@ -2633,7 +2633,7 @@ test_util_sscanf(void *arg) { unsigned u1, u2, u3; unsigned long ulng; - char s1[20], s2[10], s3[10], ch; + char s1[20], s2[10], s3[10], ch, *huge = NULL; int r; long lng1,lng2; int int1, int2; @@ -2645,7 +2645,13 @@ test_util_sscanf(void *arg) tt_int_op(-1,OP_EQ, tor_sscanf("wrong", "%5c", s1)); /* %c cannot have a number. */ tt_int_op(-1,OP_EQ, tor_sscanf("hello", "%s", s1)); /* %s needs a number. */ - tt_int_op(-1,OP_EQ, tor_sscanf("prettylongstring", "%999999s", s1)); + /* this will fail because we don't allow widths longer than 9999 */ + { + huge = tor_malloc(1000000); + r = tor_sscanf("prettylongstring", "%99999s", huge); + tor_free(huge); + tt_int_op(-1,OP_EQ, r); + } #if 0 /* GCC thinks these two are illegal. */ test_eq(-1, tor_sscanf("prettylongstring", "%0s", s1)); @@ -2751,8 +2757,13 @@ test_util_sscanf(void *arg) tt_int_op(2,OP_EQ, tor_sscanf("76trombones", "%6u%9s", &u1, s1)); /* %u%s */ tt_int_op(76,OP_EQ, u1); tt_str_op(s1,OP_EQ, "trombones"); - tt_int_op(1,OP_EQ, tor_sscanf("prettylongstring", "%999s", s1)); - tt_str_op(s1,OP_EQ, "prettylongstring"); + { + huge = tor_malloc(1000); + r = tor_sscanf("prettylongstring", "%999s", huge); + tt_int_op(1,OP_EQ, r); + tt_str_op(huge,OP_EQ, "prettylongstring"); + tor_free(huge); + } /* %s doesn't eat spaces */ tt_int_op(2,OP_EQ, tor_sscanf("hello world", "%9s %9s", s1, s2)); tt_str_op(s1,OP_EQ, "hello"); @@ -2976,7 +2987,7 @@ test_util_sscanf(void *arg) test_feq(d4, 3.2); done: - ; + tor_free(huge); } #define tt_char_op(a,op,b) tt_assert_op_type(a,op,b,char,"%c") |