]> granicus.if.org Git - p11-kit/commitdiff
attrs: Allow NULL attribute to be passed to p11_attr_hash()
authorStef Walter <stef@thewalter.net>
Mon, 13 Jan 2014 16:58:20 +0000 (17:58 +0100)
committerStef Walter <stef@thewalter.net>
Mon, 13 Jan 2014 17:11:33 +0000 (18:11 +0100)
This allows simpler lookups.

https://bugs.freedesktop.org/show_bug.cgi?id=73558

common/attrs.c
common/tests/test-attrs.c

index 9f3e522a6d8d460388dd3d1c94f33626fbd9a2f3..4a3d655748865a3ed1d30161cb65d0fb2dc1727d 100644 (file)
@@ -508,12 +508,14 @@ unsigned int
 p11_attr_hash (const void *data)
 {
        const CK_ATTRIBUTE *attr = data;
-       uint32_t hash;
+       uint32_t hash = 0;
 
-       p11_hash_murmur3 (&hash,
-                         &attr->type, sizeof (attr->type),
-                         attr->pValue, (size_t)attr->ulValueLen,
-                         NULL);
+       if (attr != NULL) {
+               p11_hash_murmur3 (&hash,
+                                 &attr->type, sizeof (attr->type),
+                                 attr->pValue, (size_t)attr->ulValueLen,
+                                 NULL);
+       }
 
        return hash;
 }
index 60871912e004773752a4e66fedeb83d6fc4831e8..79895e2d1d54640a8381f209869261c9328747f4 100644 (file)
@@ -454,6 +454,9 @@ test_hash (void)
        assert (p11_attr_hash (&overflow) != hash);
        assert (p11_attr_hash (&null) != hash);
        assert (p11_attr_hash (&content) != hash);
+
+       hash = p11_attr_hash (NULL);
+       assert (hash == 0);
 }
 
 static void