From: Mark Andrews Date: Wed, 8 Jul 2026 01:18:44 +0000 (+1000) Subject: Malformed Label: data in .private files was not detected X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=0a51e1f3268abc26cf1cf6e57f63c8431fbe811d;p=thirdparty%2Fbind9.git Malformed Label: data in .private files was not detected Check that the string encoded in the Label: field of the .private file of a key pair is NUL terminated and the correct length. Reject the .private file if it is not. --- diff --git a/lib/dns/dst_parse.c b/lib/dns/dst_parse.c index d058697ab46..8fbb00fa616 100644 --- a/lib/dns/dst_parse.c +++ b/lib/dns/dst_parse.c @@ -761,4 +761,14 @@ dst__privstruct_writefile(const dst_key_t *key, const dst_private_t *priv, return result; } +isc_result_t +dst__privelement_is_nul_terminated(const dst_private_element_t *element) { + if (element->length < 1 || element->data[element->length - 1] != 0 || + strlen((char *)element->data) != (size_t)element->length - 1) + { + return DST_R_INVALIDPRIVATEKEY; + } + return ISC_R_SUCCESS; +} + /*! \file */ diff --git a/lib/dns/dst_parse.h b/lib/dns/dst_parse.h index 80612ec253f..ddf707854a5 100644 --- a/lib/dns/dst_parse.h +++ b/lib/dns/dst_parse.h @@ -117,3 +117,7 @@ dst__privstruct_parse(dst_key_t *key, unsigned int alg, isc_lex_t *lex, isc_result_t dst__privstruct_writefile(const dst_key_t *key, const dst_private_t *priv, const char *directory); + +isc_result_t +dst__privelement_is_nul_terminated( + const dst_private_element_t *dst_private_element_t); diff --git a/lib/dns/opensslecdsa_link.c b/lib/dns/opensslecdsa_link.c index 2b7518c5760..3c8c014faad 100644 --- a/lib/dns/opensslecdsa_link.c +++ b/lib/dns/opensslecdsa_link.c @@ -548,6 +548,9 @@ opensslecdsa_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub) { /* The Engine: tag is explicitly ignored */ break; case TAG_ECDSA_LABEL: + /* NUL terminated data? */ + CHECK(dst__privelement_is_nul_terminated( + &priv.elements[i])); label = (char *)priv.elements[i].data; break; case TAG_ECDSA_PRIVATEKEY: diff --git a/lib/dns/openssleddsa_link.c b/lib/dns/openssleddsa_link.c index 0d30defcc4b..72c0d02cd5b 100644 --- a/lib/dns/openssleddsa_link.c +++ b/lib/dns/openssleddsa_link.c @@ -464,6 +464,9 @@ openssleddsa_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub) { /* The Engine: tag is explicitly ignored */ break; case TAG_EDDSA_LABEL: + /* NUL terminated data? */ + CHECK(dst__privelement_is_nul_terminated( + &priv.elements[i])); label = (char *)priv.elements[i].data; break; case TAG_EDDSA_PRIVATEKEY: diff --git a/lib/dns/opensslrsa_link.c b/lib/dns/opensslrsa_link.c index 1b6dcb40343..65a8b481b70 100644 --- a/lib/dns/opensslrsa_link.c +++ b/lib/dns/opensslrsa_link.c @@ -662,6 +662,9 @@ opensslrsa_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub) { /* The Engine: tag is explicitly ignored */ break; case TAG_RSA_LABEL: + /* NUL terminated data? */ + CHECK(dst__privelement_is_nul_terminated( + &priv.elements[i])); label = (char *)priv.elements[i].data; break; default: