diff options
author | Ilya Maximets <i.maximets@ovn.org> | 2020-11-16 20:08:22 +0100 |
---|---|---|
committer | Ilya Maximets <i.maximets@ovn.org> | 2020-11-27 13:25:44 +0100 |
commit | 7f53ec2230098bf9cc35db9b390aa2322f724b89 (patch) | |
tree | 9327f04b00e9d744eb10c25d3a0af2a1987ca5ab | |
parent | 3f8312b670eebca569d1f532ae1c94d4356708d1 (diff) | |
download | openvswitch-7f53ec2230098bf9cc35db9b390aa2322f724b89.tar.gz |
tests: Add overflow test for the sha1 library.
This is a unit test for the overflow detection issue fixed by commit
a1d2c5f5d9ed ("sha1: Fix algorithm for data bigger than 512 megabytes.")
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
Acked-by: Paolo Valerio <pvalerio@redhat.com>
Tested-by: Paolo Valerio <pvalerio@redhat.com>
-rw-r--r-- | tests/library.at | 3 | ||||
-rw-r--r-- | tests/test-sha1.c | 37 |
2 files changed, 39 insertions, 1 deletions
diff --git a/tests/library.at b/tests/library.at index a30d362e3..49d90f430 100644 --- a/tests/library.at +++ b/tests/library.at @@ -53,7 +53,8 @@ AT_CHECK([ovstest test-packets]) AT_CLEANUP AT_SETUP([SHA-1]) -AT_CHECK([ovstest test-sha1], [0], [......... +AT_KEYWORDS([sha1]) +AT_CHECK([ovstest test-sha1], [0], [.......... ]) AT_CLEANUP diff --git a/tests/test-sha1.c b/tests/test-sha1.c index b7279db6a..cc80888a7 100644 --- a/tests/test-sha1.c +++ b/tests/test-sha1.c @@ -138,6 +138,42 @@ test_big_vector(void) } static void +test_huge_vector(void) +{ + enum { SIZE = 1000000000 }; + struct test_vector vec = { + NULL, SIZE, + /* Computed by the sha1sum utility for a file with 10^9 symbols 'a'. */ + { 0xD0, 0xF3, 0xE4, 0xF2, 0xF3, 0x1C, 0x66, 0x5A, 0xBB, 0xD8, + 0xF5, 0x18, 0xE8, 0x48, 0xD5, 0xCB, 0x80, 0xCA, 0x78, 0xF7 } + }; + int chunk = random_range(SIZE / 10000); + uint8_t md[SHA1_DIGEST_SIZE]; + struct sha1_ctx sha1; + size_t i, sz; + + /* It's not user-friendly to allocate 1GB of memory for a unit test, + * so we're allocating only a small chunk and re-using it. */ + vec.data = xmalloc(chunk); + for (i = 0; i < chunk; i++) { + vec.data[i] = 'a'; + } + + sha1_init(&sha1); + for (sz = 0; sz < SIZE; sz += chunk) { + int n = sz + chunk < SIZE ? chunk : SIZE - sz; + + sha1_update(&sha1, vec.data, n); + } + sha1_final(&sha1, md); + ovs_assert(!memcmp(md, vec.output, SHA1_DIGEST_SIZE)); + + free(vec.data); + putchar('.'); + fflush(stdout); +} + +static void test_shar1_main(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) { int i; @@ -147,6 +183,7 @@ test_shar1_main(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) } test_big_vector(); + test_huge_vector(); putchar('\n'); } |