diff options
author | Pauli <paul.dale@oracle.com> | 2020-10-09 01:36:50 +0200 |
---|---|---|
committer | Pauli <paul.dale@oracle.com> | 2020-10-12 02:27:16 +0200 |
commit | 71abae18f5a27656302cb0fc076b0cd98df9e9f0 (patch) | |
tree | 261dad7d0fd7d56e1cd53b765108a829ab7a88ec /test/lhash_test.c | |
parent | coverity 1414446 out-of-bounds access: allocate \0 terminator byte to be safe (diff) | |
download | openssl-71abae18f5a27656302cb0fc076b0cd98df9e9f0.tar.xz openssl-71abae18f5a27656302cb0fc076b0cd98df9e9f0.zip |
coverity 1403324 negative array index: check for finding an unknown value and error if so (since it shouldn't happen).
Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/13091)
Diffstat (limited to 'test/lhash_test.c')
-rw-r--r-- | test/lhash_test.c | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/test/lhash_test.c b/test/lhash_test.c index c9dc8b4cee..a9aac5fb86 100644 --- a/test/lhash_test.c +++ b/test/lhash_test.c @@ -33,6 +33,7 @@ static int int_tests[] = { 65537, 13, 1, 3, -5, 6, 7, 4, -10, -12, -14, 22, 9, -17, 16, 17, -23, 35, 37, 173, 11 }; static const unsigned int n_int_tests = OSSL_NELEM(int_tests); static short int_found[OSSL_NELEM(int_tests)]; +static short int_not_found; static unsigned long int int_hash(const int *p) { @@ -56,12 +57,22 @@ static int int_find(int n) static void int_doall(int *v) { - int_found[int_find(*v)]++; + const int n = int_find(*v); + + if (n < 0) + int_not_found++; + else + int_found[n]++; } static void int_doall_arg(int *p, short *f) { - f[int_find(*p)]++; + const int n = int_find(*p); + + if (n < 0) + int_not_found++; + else + f[n]++; } IMPLEMENT_LHASH_DOALL_ARG(int, short); @@ -124,7 +135,12 @@ static int test_int_lhash(void) /* do_all */ memset(int_found, 0, sizeof(int_found)); + int_not_found = 0; lh_int_doall(h, &int_doall); + if (!TEST_int_eq(int_not_found, 0)) { + TEST_info("lhash int doall encountered a not found condition"); + goto end; + } for (i = 0; i < n_int_tests; i++) if (!TEST_int_eq(int_found[i], 1)) { TEST_info("lhash int doall %d", i); @@ -133,7 +149,12 @@ static int test_int_lhash(void) /* do_all_arg */ memset(int_found, 0, sizeof(int_found)); + int_not_found = 0; lh_int_doall_short(h, int_doall_arg, int_found); + if (!TEST_int_eq(int_not_found, 0)) { + TEST_info("lhash int doall arg encountered a not found condition"); + goto end; + } for (i = 0; i < n_int_tests; i++) if (!TEST_int_eq(int_found[i], 1)) { TEST_info("lhash int doall arg %d", i); |