]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
sm2: Allow setting 0 length SM2 dist ID param
authorTomas Mraz <tomas@openssl.org>
Wed, 6 Apr 2022 08:03:22 +0000 (10:03 +0200)
committerTomas Mraz <tomas@openssl.org>
Mon, 11 Apr 2022 09:45:04 +0000 (11:45 +0200)
Fixes #18022

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/18052)

providers/implementations/signature/sm2_sig.c

index 99460edfcea9f77d4ab7c019cfa75626d4bddd53..3de42f496eda6f72585c83c1bc09f78343f3f93f 100644 (file)
@@ -430,7 +430,7 @@ static int sm2sig_set_ctx_params(void *vpsm2ctx, const OSSL_PARAM params[])
     p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_DIST_ID);
     if (p != NULL) {
         void *tmp_id = NULL;
-        size_t tmp_idlen;
+        size_t tmp_idlen = 0;
 
         /*
          * If the 'z' digest has already been computed, the ID is set too late
@@ -438,7 +438,8 @@ static int sm2sig_set_ctx_params(void *vpsm2ctx, const OSSL_PARAM params[])
         if (!psm2ctx->flag_compute_z_digest)
             return 0;
 
-        if (!OSSL_PARAM_get_octet_string(p, &tmp_id, 0, &tmp_idlen))
+        if (p->data_size != 0
+            && !OSSL_PARAM_get_octet_string(p, &tmp_id, 0, &tmp_idlen))
             return 0;
         OPENSSL_free(psm2ctx->id);
         psm2ctx->id = tmp_id;