diff options
author | Damien Miller <djm@cvs.openbsd.org> | 2015-02-16 22:20:51 +0000 |
---|---|---|
committer | Damien Miller <djm@cvs.openbsd.org> | 2015-02-16 22:20:51 +0000 |
commit | 70834678eab6bb8eb4f56d4d0a9ec7f1e9a103f3 (patch) | |
tree | 318354ba30384e331faff7099aef248452536fd9 | |
parent | daa0e17fe043c6c1e5ba28211b702877825de77e (diff) |
check string/memory compare arguments aren't NULL
-rw-r--r-- | regress/usr.bin/ssh/unittests/test_helper/test_helper.c | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/regress/usr.bin/ssh/unittests/test_helper/test_helper.c b/regress/usr.bin/ssh/unittests/test_helper/test_helper.c index 93d8bd44db4..de873284507 100644 --- a/regress/usr.bin/ssh/unittests/test_helper/test_helper.c +++ b/regress/usr.bin/ssh/unittests/test_helper/test_helper.c @@ -1,4 +1,4 @@ -/* $OpenBSD: test_helper.c,v 1.4 2015/01/15 07:36:28 djm Exp $ */ +/* $OpenBSD: test_helper.c,v 1.5 2015/02/16 22:20:50 djm Exp $ */ /* * Copyright (c) 2011 Damien Miller <djm@mindrot.org> * @@ -300,8 +300,13 @@ void assert_string(const char *file, int line, const char *a1, const char *a2, const char *aa1, const char *aa2, enum test_predicate pred) { - int r = strcmp(aa1, aa2); + int r; + /* Verify pointers are not NULL */ + assert_ptr(file, line, a1, "NULL", aa1, NULL, TEST_NE); + assert_ptr(file, line, a2, "NULL", aa2, NULL, TEST_NE); + + r = strcmp(aa1, aa2); TEST_CHECK_INT(r, pred); test_header(file, line, a1, a2, "STRING", pred); fprintf(stderr, "%12s = %s (len %zu)\n", a1, aa1, strlen(aa1)); @@ -330,8 +335,15 @@ void assert_mem(const char *file, int line, const char *a1, const char *a2, const void *aa1, const void *aa2, size_t l, enum test_predicate pred) { - int r = memcmp(aa1, aa2, l); + int r; + if (l == 0) + return; + /* If length is >0, then verify pointers are not NULL */ + assert_ptr(file, line, a1, "NULL", aa1, NULL, TEST_NE); + assert_ptr(file, line, a2, "NULL", aa2, NULL, TEST_NE); + + r = memcmp(aa1, aa2, l); TEST_CHECK_INT(r, pred); test_header(file, line, a1, a2, "STRING", pred); fprintf(stderr, "%12s = %s (len %zu)\n", a1, tohex(aa1, MIN(l, 256)), l); @@ -358,11 +370,15 @@ assert_mem_filled(const char *file, int line, const char *a1, const void *aa1, u_char v, size_t l, enum test_predicate pred) { size_t where = -1; - int r = memvalcmp(aa1, v, l, &where); + int r; char tmp[64]; if (l == 0) return; + /* If length is >0, then verify the pointer is not NULL */ + assert_ptr(file, line, a1, "NULL", aa1, NULL, TEST_NE); + + r = memvalcmp(aa1, v, l, &where); TEST_CHECK_INT(r, pred); test_header(file, line, a1, NULL, "MEM_ZERO", pred); fprintf(stderr, "%20s = %s%s (len %zu)\n", a1, |