support: Report NULL blobs explicitly in TEST_COMPARE

Message ID 87ftpvr0nm.fsf@oldenburg2.str.redhat.com
State Superseded
Headers

Commit Message

Florian Weimer May 3, 2019, 3:57 p.m. UTC
  Provide an explicit diagnostic if the length is positive, and
do not just crash with a null pointer dereference.  Null pointers
are only valid if the length is zero, so this can only happen with
a faulty test.

2019-05-03  Florian Weimer  <fweimer@redhat.com>

	* support/support_test_compare_blob.c (report_blob): Report
	incorrect NULL blobs.
  

Patch

diff --git a/support/support_test_compare_blob.c b/support/support_test_compare_blob.c
index 5bcb03418c..00491b0df1 100644
--- a/support/support_test_compare_blob.c
+++ b/support/support_test_compare_blob.c
@@ -33,7 +33,9 @@  static void
 report_blob (const char *what, const unsigned char *blob,
              unsigned long int length, const char *expr)
 {
-  if (length > 0)
+  if (blob == NULL)
+    printf ("  %s (evaluated from %s): NULL\n", what, expr);
+  else if (length > 0)
     {
       printf ("  %s (evaluated from %s):\n", what, expr);
       char *quoted = support_quote_blob (blob, length);