diff options
author | Nick Mathewson <nickm@torproject.org> | 2014-09-10 23:58:02 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2014-09-10 23:58:02 -0400 |
commit | 5126bc2ebd9ae67449e3c4f18828acb895d86308 (patch) | |
tree | 95fa0afd038eb513b1c03218bf4b1ef64e257280 /src/test/test_util.c | |
parent | d2463c0cfee066111c3a72d188cd897957aa2988 (diff) | |
download | tor-5126bc2ebd9ae67449e3c4f18828acb895d86308.tar.gz tor-5126bc2ebd9ae67449e3c4f18828acb895d86308.zip |
Extra tests for tor_memeq and memcmp
(Patch from teor; part of 13104)
Diffstat (limited to 'src/test/test_util.c')
-rw-r--r-- | src/test/test_util.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/test/test_util.c b/src/test/test_util.c index 16a2927e4d..f091fc95a1 100644 --- a/src/test/test_util.c +++ b/src/test/test_util.c @@ -3251,6 +3251,25 @@ test_util_di_ops(void) test_eq(neq1, !eq1); } + /* exhaustively white-box test tor_memeq + * against each possible (single-byte) bit difference + * some arithmetic bugs only appear with certain bit patterns */ + const uint8_t z = 0; + uint8_t ii = 0; + for (i = 0; i < 256; i++) { + ii = (uint8_t)i; + test_eq(tor_memeq(&z, &ii, 1), z == ii); + } + + /* exhaustively white-box test tor_memcmp + * against each possible single-byte numeric difference + * some arithmetic bugs only appear with certain bit patterns */ + for (i = 0; i < 256; i++) { + ii = (uint8_t)i; + test_eq(tor_memcmp(&z, &ii, 1) > 0 ? GT : EQ, z > ii ? GT : EQ); + test_eq(tor_memcmp(&ii, &z, 1) < 0 ? LT : EQ, ii < z ? LT : EQ); + } + tt_int_op(1, ==, safe_mem_is_zero("", 0)); tt_int_op(1, ==, safe_mem_is_zero("", 1)); tt_int_op(0, ==, safe_mem_is_zero("a", 1)); |