]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Add isc_hashmap_find() DbC check for valuep
authorOndřej Surý <ondrej@isc.org>
Mon, 13 Feb 2023 15:16:26 +0000 (16:16 +0100)
committerOndřej Surý <ondrej@isc.org>
Wed, 15 Feb 2023 08:30:04 +0000 (09:30 +0100)
This adds DbC check, so we don't pass non-NULL memory for a valued to
the isc_hashmap_find() function.

lib/isc/hashmap.c
tests/isc/hashmap_test.c

index 2ea7a251821287b9896d347ffb953fb1e39885a6..1a8f15e0a2957a89b2425a28a142b3df1277bb91 100644 (file)
@@ -332,8 +332,9 @@ isc_hashmap_find(const isc_hashmap_t *hashmap, const uint32_t *hashvalp,
                 const void *key, uint32_t keysize, void **valuep) {
        REQUIRE(ISC_HASHMAP_VALID(hashmap));
        REQUIRE(key != NULL && keysize <= UINT16_MAX);
+       REQUIRE(valuep == NULL || *valuep == NULL);
 
-       hashmap_node_t *node;
+       hashmap_node_t *node = NULL;
        uint8_t idx = hashmap->hindex;
        uint32_t hashval = (hashvalp != NULL)
                                   ? *hashvalp
index 99b7951f57c1ab3bb75fcd82afdff86a8051184c..b7e755a1fecba0913d3e3c3ffc9e3d4ebc071ccc 100644 (file)
@@ -381,7 +381,6 @@ ISC_RUN_TEST_IMPL(isc_hashmap_case) {
        test_node_t lower = { .key = "isc_hashmap_case" };
        test_node_t upper = { .key = "ISC_HASHMAP_CASE" };
        test_node_t mixed = { .key = "IsC_hAsHmAp_CaSe" };
-       test_node_t *value;
 
        isc_hashmap_create(mctx, 1, ISC_HASHMAP_CASE_SENSITIVE, &hashmap);
 
@@ -398,7 +397,7 @@ ISC_RUN_TEST_IMPL(isc_hashmap_case) {
        assert_int_equal(result, ISC_R_SUCCESS);
 
        result = isc_hashmap_find(hashmap, NULL, mixed.key, strlen(mixed.key),
-                                 (void *)&value);
+                                 &(void *){ NULL });
        assert_int_equal(result, ISC_R_NOTFOUND);
 
        isc_hashmap_destroy(&hashmap);
@@ -418,7 +417,7 @@ ISC_RUN_TEST_IMPL(isc_hashmap_case) {
        assert_int_equal(result, ISC_R_EXISTS);
 
        result = isc_hashmap_find(hashmap, NULL, mixed.key, strlen(mixed.key),
-                                 (void *)&value);
+                                 &(void *){ NULL });
        assert_int_equal(result, ISC_R_SUCCESS);
 
        isc_hashmap_destroy(&hashmap);