aboutsummaryrefslogtreecommitdiff
path: root/test/stack_test.c
diff options
context:
space:
mode:
authorMatt Caswell <matt@openssl.org>2017-03-16 17:32:32 +0000
committerMatt Caswell <matt@openssl.org>2017-03-17 10:09:46 +0000
commit3fb2c3e452c9adea24edf8b0b96f6325c0473ee9 (patch)
tree0f68a2578498632447b3a491aee7dc2483cece10 /test/stack_test.c
parent508ee8f5ffc5a3ab1bb10b14c0331393d938326f (diff)
downloadopenssl-3fb2c3e452c9adea24edf8b0b96f6325c0473ee9.zip
openssl-3fb2c3e452c9adea24edf8b0b96f6325c0473ee9.tar.gz
openssl-3fb2c3e452c9adea24edf8b0b96f6325c0473ee9.tar.bz2
Fix some undefined behaviour in stack test
At one point the stack was passing a pointer of the element *before* an array which is undefined. Reviewed-by: Rich Salz <rsalz@openssl.org> Reviewed-by: Richard Levitte <levitte@openssl.org> (Merged from https://github.com/openssl/openssl/pull/2971)
Diffstat (limited to 'test/stack_test.c')
-rw-r--r--test/stack_test.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/test/stack_test.c b/test/stack_test.c
index f04f6af..4325766 100644
--- a/test/stack_test.c
+++ b/test/stack_test.c
@@ -57,6 +57,7 @@ static int int_compare(const int *const *a, const int *const *b)
static int test_int_stack(void)
{
static int v[] = { 1, 2, -4, 16, 999, 1, -173, 1, 9 };
+ static int notpresent = -1;
const int n = OSSL_NELEM(v);
static struct {
int value;
@@ -108,18 +109,26 @@ static int test_int_stack(void)
}
/* find unsorted -- the pointers are compared */
- for (i = 0; i < n_finds; i++)
- if (sk_sint_find(s, v + finds[i].unsorted) != finds[i].unsorted) {
+ for (i = 0; i < n_finds; i++) {
+ int *val = (finds[i].unsorted == -1) ? &notpresent
+ : v + finds[i].unsorted;
+
+ if (sk_sint_find(s, val) != finds[i].unsorted) {
fprintf(stderr, "test int unsorted find %d\n", i);
goto end;
}
+ }
/* find_ex unsorted */
- for (i = 0; i < n_finds; i++)
- if (sk_sint_find_ex(s, v + finds[i].unsorted) != finds[i].unsorted) {
+ for (i = 0; i < n_finds; i++) {
+ int *val = (finds[i].unsorted == -1) ? &notpresent
+ : v + finds[i].unsorted;
+
+ if (sk_sint_find_ex(s, val) != finds[i].unsorted) {
fprintf(stderr, "test int unsorted find_ex %d\n", i);
goto end;
}
+ }
/* sorting */
if (sk_sint_is_sorted(s)) {