From bf6be24be37beceecd6c279047f4376c42e120c6 Mon Sep 17 00:00:00 2001 From: "Evgeny Grin (Karlson2k)" Date: Sun, 12 Sep 2021 18:31:54 +0300 Subject: [PATCH] test_postprocessor: fixed call of memcmp() with NULL pointers --- src/microhttpd/test_postprocessor.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/microhttpd/test_postprocessor.c b/src/microhttpd/test_postprocessor.c index 17d09c91..b3e12323 100644 --- a/src/microhttpd/test_postprocessor.c +++ b/src/microhttpd/test_postprocessor.c @@ -105,6 +105,17 @@ mismatch (const char *a, const char *b) } +static int +mismatch2 (const char *data, const char *expected, size_t offset, size_t size) +{ + if (data == expected) + return 0; + if ((data == NULL) || (expected == NULL)) + return 1; + return 0 != memcmp (data, expected + offset, size); +} + + static enum MHD_Result value_checker (void *cls, enum MHD_ValueKind kind, @@ -144,9 +155,7 @@ value_checker (void *cls, (mismatch (filename, expct->fname)) || (mismatch (content_type, expct->cnt_type)) || (mismatch (transfer_encoding, expct->tr_enc)) || - (0 != memcmp (data, - &expct->data[off], - size))) + (mismatch2 (data, expct->data, off, size))) { *idxp = (unsigned int) -1; fprintf (stderr, @@ -171,7 +180,7 @@ value_checker (void *cls, (mismatch (filename, expct->fname)), (mismatch (content_type, expct->cnt_type)), (mismatch (transfer_encoding, expct->tr_enc)), - (0 != memcmp (data, &expct->data[off], size))); + (mismatch2 (data, expct->data, off, size))); return MHD_NO; } if ( ( (NULL == expct->data) &&