[glib/wip/smcv/memcmp-null: 1/2] gvariant: Avoid memcmp (NULL, ., 0) or memcmp (., NULL, 0)



commit 2465e64c93a1baba65474f676e119ac8522c3a88
Author: Simon McVittie <smcv collabora com>
Date:   Mon Nov 4 13:40:40 2019 +0000

    gvariant: Avoid memcmp (NULL, ., 0) or memcmp (., NULL, 0)
    
    Similar to 3837b83f, glibc memcmp is declared with the first two
    arguments annotated as non-null via an attribute, which results in the
    undefined behaviour sanitizer considering it to be UB to pass a null
    pointer there (even if we are comparing 0 bytes, and hence not actually
    dereferencing the pointer).
    
    This shows up in /gvariant/serialiser/children when run with the
    undefined behaviour sanitizer.
    
    Signed-off-by: Simon McVittie <smcv collabora com>

 glib/gvariant.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
---
diff --git a/glib/gvariant.c b/glib/gvariant.c
index b61bf7278..d7ec8dc70 100644
--- a/glib/gvariant.c
+++ b/glib/gvariant.c
@@ -2765,7 +2765,10 @@ g_variant_equal (gconstpointer one,
       data_one = g_variant_get_data ((GVariant *) one);
       data_two = g_variant_get_data ((GVariant *) two);
 
-      equal = memcmp (data_one, data_two, size_one) == 0;
+      if (size_one)
+        equal = memcmp (data_one, data_two, size_one) == 0;
+      else
+        equal = TRUE;
     }
   else
     {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]