From 21d828241b47c1fbdc6083c20b21dd95f48acc87 Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Tue, 29 Nov 2022 16:11:51 +1100 Subject: [PATCH] dns_view_untrust modifies dnskey->flags when it shouldn't Copy the structure and declare dnskey as const. --- lib/dns/include/dns/view.h | 2 +- lib/dns/view.c | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/dns/include/dns/view.h b/lib/dns/include/dns/view.h index 32746c38db..a552327bad 100644 --- a/lib/dns/include/dns/view.h +++ b/lib/dns/include/dns/view.h @@ -1045,7 +1045,7 @@ dns_view_ntacovers(dns_view_t *view, isc_stdtime_t now, const dns_name_t *name, void dns_view_untrust(dns_view_t *view, const dns_name_t *keyname, - dns_rdata_dnskey_t *dnskey); + const dns_rdata_dnskey_t *dnskey); /*%< * Remove keys that match 'keyname' and 'dnskey' from the views trust * anchors. diff --git a/lib/dns/view.c b/lib/dns/view.c index 7752a9d0ee..133d6775bb 100644 --- a/lib/dns/view.c +++ b/lib/dns/view.c @@ -1639,26 +1639,28 @@ dns_view_issecuredomain(dns_view_t *view, const dns_name_t *name, void dns_view_untrust(dns_view_t *view, const dns_name_t *keyname, - dns_rdata_dnskey_t *dnskey) { + const dns_rdata_dnskey_t *dnskey) { isc_result_t result; dns_keytable_t *sr = NULL; + dns_rdata_dnskey_t tmpkey; REQUIRE(DNS_VIEW_VALID(view)); REQUIRE(keyname != NULL); REQUIRE(dnskey != NULL); - /* - * Clear the revoke bit, if set, so that the key will match what's - * in secroots now. - */ - dnskey->flags &= ~DNS_KEYFLAG_REVOKE; - result = dns_view_getsecroots(view, &sr); if (result != ISC_R_SUCCESS) { return; } - result = dns_keytable_deletekey(sr, keyname, dnskey); + /* + * Clear the revoke bit, if set, so that the key will match what's + * in secroots now. + */ + tmpkey = *dnskey; + tmpkey.flags &= ~DNS_KEYFLAG_REVOKE; + + result = dns_keytable_deletekey(sr, keyname, &tmpkey); if (result == ISC_R_SUCCESS) { /* * If key was found in secroots, then it was a