summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2015-02-16 22:20:50 +0000
committerDamien Miller <djm@mindrot.org>2015-02-17 09:34:48 +1100
commit68a5d647ccf0fb6782b2f749433a1eee5bc9044b (patch)
treed560dd86e0d0c17f19798f6d5da0f4cc5d3c37dc
parentef575ef20d09f20722e26b45dab80b3620469687 (diff)
upstream commit
check string/memory compare arguments aren't NULL
-rw-r--r--regress/unittests/test_helper/test_helper.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/regress/unittests/test_helper/test_helper.c b/regress/unittests/test_helper/test_helper.c
index 400555ed2..034af938c 100644
--- a/regress/unittests/test_helper/test_helper.c
+++ b/regress/unittests/test_helper/test_helper.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: test_helper.c,v 1.4 2015/01/15 07:36:28 djm Exp $ */ 1/* $OpenBSD: test_helper.c,v 1.5 2015/02/16 22:20:50 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2011 Damien Miller <djm@mindrot.org> 3 * Copyright (c) 2011 Damien Miller <djm@mindrot.org>
4 * 4 *
@@ -319,8 +319,13 @@ void
319assert_string(const char *file, int line, const char *a1, const char *a2, 319assert_string(const char *file, int line, const char *a1, const char *a2,
320 const char *aa1, const char *aa2, enum test_predicate pred) 320 const char *aa1, const char *aa2, enum test_predicate pred)
321{ 321{
322 int r = strcmp(aa1, aa2); 322 int r;
323 323
324 /* Verify pointers are not NULL */
325 assert_ptr(file, line, a1, "NULL", aa1, NULL, TEST_NE);
326 assert_ptr(file, line, a2, "NULL", aa2, NULL, TEST_NE);
327
328 r = strcmp(aa1, aa2);
324 TEST_CHECK_INT(r, pred); 329 TEST_CHECK_INT(r, pred);
325 test_header(file, line, a1, a2, "STRING", pred); 330 test_header(file, line, a1, a2, "STRING", pred);
326 fprintf(stderr, "%12s = %s (len %zu)\n", a1, aa1, strlen(aa1)); 331 fprintf(stderr, "%12s = %s (len %zu)\n", a1, aa1, strlen(aa1));
@@ -349,8 +354,15 @@ void
349assert_mem(const char *file, int line, const char *a1, const char *a2, 354assert_mem(const char *file, int line, const char *a1, const char *a2,
350 const void *aa1, const void *aa2, size_t l, enum test_predicate pred) 355 const void *aa1, const void *aa2, size_t l, enum test_predicate pred)
351{ 356{
352 int r = memcmp(aa1, aa2, l); 357 int r;
353 358
359 if (l == 0)
360 return;
361 /* If length is >0, then verify pointers are not NULL */
362 assert_ptr(file, line, a1, "NULL", aa1, NULL, TEST_NE);
363 assert_ptr(file, line, a2, "NULL", aa2, NULL, TEST_NE);
364
365 r = memcmp(aa1, aa2, l);
354 TEST_CHECK_INT(r, pred); 366 TEST_CHECK_INT(r, pred);
355 test_header(file, line, a1, a2, "STRING", pred); 367 test_header(file, line, a1, a2, "STRING", pred);
356 fprintf(stderr, "%12s = %s (len %zu)\n", a1, tohex(aa1, MIN(l, 256)), l); 368 fprintf(stderr, "%12s = %s (len %zu)\n", a1, tohex(aa1, MIN(l, 256)), l);
@@ -377,11 +389,15 @@ assert_mem_filled(const char *file, int line, const char *a1,
377 const void *aa1, u_char v, size_t l, enum test_predicate pred) 389 const void *aa1, u_char v, size_t l, enum test_predicate pred)
378{ 390{
379 size_t where = -1; 391 size_t where = -1;
380 int r = memvalcmp(aa1, v, l, &where); 392 int r;
381 char tmp[64]; 393 char tmp[64];
382 394
383 if (l == 0) 395 if (l == 0)
384 return; 396 return;
397 /* If length is >0, then verify the pointer is not NULL */
398 assert_ptr(file, line, a1, "NULL", aa1, NULL, TEST_NE);
399
400 r = memvalcmp(aa1, v, l, &where);
385 TEST_CHECK_INT(r, pred); 401 TEST_CHECK_INT(r, pred);
386 test_header(file, line, a1, NULL, "MEM_ZERO", pred); 402 test_header(file, line, a1, NULL, "MEM_ZERO", pred);
387 fprintf(stderr, "%20s = %s%s (len %zu)\n", a1, 403 fprintf(stderr, "%20s = %s%s (len %zu)\n", a1,