]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Suppress duplicate digest types
authorMatthijs Mekking <matthijs@isc.org>
Mon, 13 Feb 2023 15:11:46 +0000 (16:11 +0100)
committerMatthijs Mekking <matthijs@isc.org>
Tue, 28 Feb 2023 08:38:17 +0000 (09:38 +0100)
When adding CDS digest types to the kasp structure, check for
duplicates.

lib/dns/kasp.c

index 5a9d907e7cf6b02c0de26a8e1983177ae2424f16..ed3a1303cce6e036c614de8610f0a88868e8fc8e 100644 (file)
@@ -529,14 +529,27 @@ dns_kasp_digests(dns_kasp_t *kasp) {
 
 void
 dns_kasp_adddigest(dns_kasp_t *kasp, dns_dsdigest_t alg) {
+       dns_kasp_digest_t *digest;
+
        REQUIRE(DNS_KASP_VALID(kasp));
        REQUIRE(!kasp->frozen);
 
-       if (dst_ds_digest_supported(alg)) {
-               dns_kasp_digest_t *digest = isc_mem_get(kasp->mctx,
-                                                       sizeof(*digest));
-               digest->digest = alg;
-               ISC_LINK_INIT(digest, link);
-               ISC_LIST_APPEND(kasp->digests, digest, link);
+       /* Suppress unsupported algorithms */
+       if (!dst_ds_digest_supported(alg)) {
+               return;
+       }
+
+       /* Suppress duplicates */
+       for (dns_kasp_digest_t *d = ISC_LIST_HEAD(kasp->digests); d != NULL;
+            d = ISC_LIST_NEXT(d, link))
+       {
+               if (d->digest == alg) {
+                       return;
+               }
        }
+
+       digest = isc_mem_get(kasp->mctx, sizeof(*digest));
+       digest->digest = alg;
+       ISC_LINK_INIT(digest, link);
+       ISC_LIST_APPEND(kasp->digests, digest, link);
 }