]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Fix KASP key leaks on keystore lookup failure
authorOndřej Surý <ondrej@isc.org>
Sat, 14 Mar 2026 11:54:50 +0000 (12:54 +0100)
committerOndřej Surý <ondrej@isc.org>
Sat, 14 Mar 2026 12:58:32 +0000 (13:58 +0100)
In both cfg_kasp_fromconfig() and cfg_kasp_builtinconfig(), the
newly allocated KASP key was not destroyed when the keystore
lookup failed.

lib/isccfg/kaspconf.c

index 6593f78145a23734a8d0461473aaf0e982505d5e..ab4df8a51d510337217b516f89714f409abbef0e 100644 (file)
@@ -817,6 +817,7 @@ cfg_kasp_fromconfig(const cfg_obj_t *config, dns_kasp_t *default_kasp,
                                                    "find keystore (%s)",
                                                    isc_result_totext(result));
                                }
+                               dns_kasp_key_destroy(new_key);
                                goto cleanup;
                        }
                        dns_kasp_addkey(kasp, new_key);
@@ -930,9 +931,13 @@ cfg_kasp_builtinconfig(isc_mem_t *mctx, const char *name,
                new_key->lifetime = 0;
                new_key->algorithm = DST_ALG_ECDSA256;
                new_key->length = 256;
-               CHECK(dns_keystorelist_find(keystorelist,
-                                           DNS_KEYSTORE_KEYDIRECTORY,
-                                           &new_key->keystore));
+               result = dns_keystorelist_find(keystorelist,
+                                              DNS_KEYSTORE_KEYDIRECTORY,
+                                              &new_key->keystore);
+               if (result != ISC_R_SUCCESS) {
+                       dns_kasp_key_destroy(new_key);
+                       goto cleanup;
+               }
                dns_kasp_addkey(kasp, new_key);
        }