]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Malformed Label: data in .private files was not detected 12364/head
authorMark Andrews <marka@isc.org>
Wed, 8 Jul 2026 01:18:44 +0000 (11:18 +1000)
committerMark Andrews <marka@isc.org>
Thu, 16 Jul 2026 19:17:09 +0000 (05:17 +1000)
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.

lib/dns/dst_parse.c
lib/dns/dst_parse.h
lib/dns/opensslecdsa_link.c
lib/dns/openssleddsa_link.c
lib/dns/opensslrsa_link.c

index d058697ab46209b7f7ae4eb0e0309523ad36f257..8fbb00fa6161839bb490a981fe2127bf3961f4b1 100644 (file)
@@ -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 */
index 80612ec253faf8bcbb1968573b5c02fd457aded6..ddf707854a57fc5b502223ef249d10e36e04a417 100644 (file)
@@ -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);
index 2b7518c5760a701f46715178bc510da527bfe482..3c8c014faad0e86700505a42218adbd77288853d 100644 (file)
@@ -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:
index 0d30defcc4be7db17df3f01cdd3fdec77800b02e..72c0d02cd5bedfe9bf5d7f07b2ae7bd2774a114e 100644 (file)
@@ -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:
index 1b6dcb40343591355c6c73671b0d8d0f13db4c3e..65a8b481b708401ace34a5f4b5026c803f151d13 100644 (file)
@@ -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: