From 28fe8104eed82d2053b9e2a2d06bd29cb3085ae5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Mon, 13 Feb 2023 16:16:26 +0100 Subject: [PATCH] Add isc_hashmap_find() DbC check for valuep 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 | 3 ++- tests/isc/hashmap_test.c | 5 ++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/isc/hashmap.c b/lib/isc/hashmap.c index 2ea7a25182..1a8f15e0a2 100644 --- a/lib/isc/hashmap.c +++ b/lib/isc/hashmap.c @@ -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 diff --git a/tests/isc/hashmap_test.c b/tests/isc/hashmap_test.c index 99b7951f57..b7e755a1fe 100644 --- a/tests/isc/hashmap_test.c +++ b/tests/isc/hashmap_test.c @@ -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);