unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] support: Report NULL blobs explicitly in TEST_COMPARE
@ 2019-05-03 15:57 Florian Weimer
  2019-05-03 16:53 ` Florian Weimer
  0 siblings, 1 reply; 3+ messages in thread
From: Florian Weimer @ 2019-05-03 15:57 UTC (permalink / raw)
  To: libc-alpha

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.

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);

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] support: Report NULL blobs explicitly in TEST_COMPARE
  2019-05-03 15:57 [PATCH] support: Report NULL blobs explicitly in TEST_COMPARE Florian Weimer
@ 2019-05-03 16:53 ` Florian Weimer
  2019-05-16 13:12   ` Florian Weimer
  0 siblings, 1 reply; 3+ messages in thread
From: Florian Weimer @ 2019-05-03 16:53 UTC (permalink / raw)
  To: libc-alpha

* Florian Weimer:

> 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.
>
> 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);

Hmph, this patch is better because it does not change test failure
output with for NULL with zero length:

diff --git a/support/support_test_compare_blob.c b/support/support_test_compare_blob.c
index 5bcb03418c..37f012257d 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 && length > 0)
+    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);

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] support: Report NULL blobs explicitly in TEST_COMPARE
  2019-05-03 16:53 ` Florian Weimer
@ 2019-05-16 13:12   ` Florian Weimer
  0 siblings, 0 replies; 3+ messages in thread
From: Florian Weimer @ 2019-05-16 13:12 UTC (permalink / raw)
  To: libc-alpha

* Florian Weimer:

> * Florian Weimer:
>
>> 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.

> Hmph, this patch is better because it does not change test failure
> output with for NULL with zero length:

I've pushed the second patch.

Thanks,
Florian

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-05-16 13:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-03 15:57 [PATCH] support: Report NULL blobs explicitly in TEST_COMPARE Florian Weimer
2019-05-03 16:53 ` Florian Weimer
2019-05-16 13:12   ` Florian Weimer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).