From 52364cd8d9e58110bd2cad4572cefd08b09782cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag-Erling=20Sm=C3=B8rgrav?= Date: Wed, 20 Feb 2019 14:07:47 +0100 Subject: [PATCH] Fix double-NULL case. Fix null pointer dereference in t_compare_mem() and t_compare_str() when both the expected value and the received value are NULL. --- lib/test/cryb_t_compare.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/test/cryb_t_compare.c b/lib/test/cryb_t_compare.c index 4e35e78..4234457 100644 --- a/lib/test/cryb_t_compare.c +++ b/lib/test/cryb_t_compare.c @@ -110,7 +110,8 @@ t_compare_mem(const void *expected, const void *received, size_t len) t_printv("\n"); t_printv("received null pointer\n"); return (0); - } else if (memcmp(expected, received, len) != 0) { + } else if (expected != NULL && received != NULL && + memcmp(expected, received, len) != 0) { t_printv("expected "); t_printv_hex(expected, len); t_printv("\n"); @@ -137,7 +138,8 @@ t_compare_str(const char *expected, const char *received) t_printv("expected \"%s\"\n", expected); t_printv("received null pointer\n"); return (0); - } else if (strcmp(expected, received) != 0) { + } else if (expected != NULL && received != NULL && + strcmp(expected, received) != 0) { t_printv("expected %s\n", expected); t_printv("received %s\n", received); return (0);