Skip to content

Commit

Permalink
Fix undefined behaviour in EC_GROUP_new_from_ecparameters
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
(Merged from openssl#18365)
  • Loading branch information
bernd-edlinger committed May 24, 2022
1 parent 22a96c6 commit 97de614
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions crypto/ec/ec_asn1.c
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,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) {
ERR_raise(ERR_LIB_EC, EC_R_ASN1_ERROR);
goto err;
}
OPENSSL_free(ret->seed);
if ((ret->seed = OPENSSL_malloc(params->curve->seed->length)) == NULL) {
ERR_raise(ERR_LIB_EC, ERR_R_MALLOC_FAILURE);
Expand Down

0 comments on commit 97de614

Please sign in to comment.