]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
OSSL_PARAM_BLD_push_octet_*(): Allow NULL buffer with 0 bsize
authorTomas Mraz <tomas@openssl.foundation>
Wed, 8 Apr 2026 15:38:51 +0000 (17:38 +0200)
committerNikola Pajkovsky <nikolap@openssl.org>
Mon, 13 Apr 2026 07:47:42 +0000 (09:47 +0200)
Fixes #30728

Reviewed-by: Eugene Syromiatnikov <esyr@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
MergeDate: Mon Apr 13 07:47:44 2026
(Merged from https://github.com/openssl/openssl/pull/30730)

crypto/param_build.c
test/param_build_test.c

index d4ada8f767ebebb0a3243cee00664af401c046fa..c268730db271cf91f2a9013ab8dc7362673cc01e 100644 (file)
@@ -345,7 +345,7 @@ int OSSL_PARAM_BLD_push_utf8_ptr(OSSL_PARAM_BLD *bld, const char *key,
 {
     OSSL_PARAM_BLD_DEF *pd;
 
-    if (bld == NULL || key == NULL) {
+    if (bld == NULL || key == NULL || buf == NULL) {
         ERR_raise(ERR_LIB_CRYPTO, ERR_R_PASSED_NULL_PARAMETER);
         return 0;
     }
@@ -365,7 +365,7 @@ int OSSL_PARAM_BLD_push_octet_string(OSSL_PARAM_BLD *bld, const char *key,
     OSSL_PARAM_BLD_DEF *pd;
     int secure;
 
-    if (bld == NULL || key == NULL || buf == NULL) {
+    if (bld == NULL || key == NULL || (buf == NULL && bsize != 0)) {
         ERR_raise(ERR_LIB_CRYPTO, ERR_R_PASSED_NULL_PARAMETER);
         return 0;
     }
@@ -383,7 +383,7 @@ int OSSL_PARAM_BLD_push_octet_ptr(OSSL_PARAM_BLD *bld, const char *key,
 {
     OSSL_PARAM_BLD_DEF *pd;
 
-    if (bld == NULL || key == NULL) {
+    if (bld == NULL || key == NULL || (buf == NULL && bsize != 0)) {
         ERR_raise(ERR_LIB_CRYPTO, ERR_R_PASSED_NULL_PARAMETER);
         return 0;
     }
index 3b90a5e829ccceb63f1b3206a4518ae032c1b480..bac0afcb34410ed49e54b436baf4b06f7fcad668 100644 (file)
@@ -117,8 +117,12 @@ static int template_public_test(int tstid)
         || !TEST_true(OSSL_PARAM_BLD_push_BN(bld, "negativebignumber", nbn))
         || !TEST_true(OSSL_PARAM_BLD_push_utf8_string(bld, "utf8_s", "foo",
             sizeof("foo")))
+        || !TEST_true(OSSL_PARAM_BLD_push_octet_string(bld, "octet_s", NULL,
+            0))
         || !TEST_true(OSSL_PARAM_BLD_push_utf8_ptr(bld, "utf8_p", "bar-boom",
             0))
+        || !TEST_true(OSSL_PARAM_BLD_push_octet_ptr(bld, "octet_p", NULL,
+            0))
         || !TEST_true(OSSL_PARAM_BLD_push_int(bld, "i", -6))
         || !TEST_ptr(params_blt = OSSL_PARAM_BLD_to_param(bld)))
         goto err;
@@ -189,10 +193,16 @@ static int template_public_test(int tstid)
         || !TEST_str_eq(p->data, "foo")
         || !TEST_true(OSSL_PARAM_get_utf8_string(p, &utf, 0))
         || !TEST_str_eq(utf, "foo")
+        /* Check NULL octet string */
+        || !TEST_ptr(p = OSSL_PARAM_locate(params, "octet_s"))
+        || !TEST_size_t_eq(p->data_size, 0)
         /* Check UTF8 pointer */
         || !TEST_ptr(p = OSSL_PARAM_locate(params, "utf8_p"))
         || !TEST_true(OSSL_PARAM_get_utf8_ptr(p, &cutf))
         || !TEST_str_eq(cutf, "bar-boom")
+        /* Check NULL octet ptr */
+        || !TEST_ptr(p = OSSL_PARAM_locate(params, "octet_p"))
+        || !TEST_size_t_eq(p->data_size, 0)
         /* Check BN (zero BN becomes unsigned integer) */
         || !TEST_ptr(p = OSSL_PARAM_locate(params, "zeronumber"))
         || !TEST_str_eq(p->key, "zeronumber")