]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Fix undefined behaviour in EC_GROUP_new_from_ecparameters
authorBernd Edlinger <bernd.edlinger@hotmail.de>
Fri, 20 May 2022 14:54:41 +0000 (16:54 +0200)
committerBernd Edlinger <bernd.edlinger@hotmail.de>
Tue, 24 May 2022 09:47:37 +0000 (11:47 +0200)
This happens for instance with
fuzz/corpora/asn1/65cf44e85614c62f10cf3b7a7184c26293a19e4a
and causes the OPENSSL_malloc below to choke on the
zero length allocation request.

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/18363)

crypto/ec/ec_asn1.c

index 4335b3da1a54f0652076eb40fae41fe74bcab01d..ad9a54dc50a176356b6c873bc0cd0939afaf55ae 100644 (file)
@@ -751,6 +751,16 @@ EC_GROUP *EC_GROUP_new_from_ecparameters(const ECPARAMETERS *params)
 
     /* extract seed (optional) */
     if (params->curve->seed != NULL) {
+        /*
+         * This happens for instance with
+         * fuzz/corpora/asn1/65cf44e85614c62f10cf3b7a7184c26293a19e4a
+         * and causes the OPENSSL_malloc below to choke on the
+         * zero length allocation request.
+         */
+        if (params->curve->seed->length == 0) {
+            ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, EC_R_ASN1_ERROR);
+            goto err;
+        }
         OPENSSL_free(ret->seed);
         if ((ret->seed = OPENSSL_malloc(params->curve->seed->length)) == NULL) {
             ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, ERR_R_MALLOC_FAILURE);