提交 515c728d 编写于 作者: B Bernd Edlinger

Fix potential memory leaks with BN_to_ASN1_INTEGER

Reviewed-by: NPaul Dale <paul.dale@oracle.com>
Reviewed-by: NMatt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9833)

(cherry picked from commit f28bc7d386b25fb75625d0c62c6b2e6d21de0d09)
上级 86ed7867
...@@ -446,6 +446,7 @@ ECPARAMETERS *EC_GROUP_get_ecparameters(const EC_GROUP *group, ...@@ -446,6 +446,7 @@ ECPARAMETERS *EC_GROUP_get_ecparameters(const EC_GROUP *group,
unsigned char *buffer = NULL; unsigned char *buffer = NULL;
const EC_POINT *point = NULL; const EC_POINT *point = NULL;
point_conversion_form_t form; point_conversion_form_t form;
ASN1_INTEGER *orig;
if (params == NULL) { if (params == NULL) {
if ((ret = ECPARAMETERS_new()) == NULL) { if ((ret = ECPARAMETERS_new()) == NULL) {
...@@ -496,8 +497,9 @@ ECPARAMETERS *EC_GROUP_get_ecparameters(const EC_GROUP *group, ...@@ -496,8 +497,9 @@ ECPARAMETERS *EC_GROUP_get_ecparameters(const EC_GROUP *group,
ECerr(EC_F_EC_GROUP_GET_ECPARAMETERS, ERR_R_EC_LIB); ECerr(EC_F_EC_GROUP_GET_ECPARAMETERS, ERR_R_EC_LIB);
goto err; goto err;
} }
ret->order = BN_to_ASN1_INTEGER(tmp, ret->order); ret->order = BN_to_ASN1_INTEGER(tmp, orig = ret->order);
if (ret->order == NULL) { if (ret->order == NULL) {
ret->order = orig;
ECerr(EC_F_EC_GROUP_GET_ECPARAMETERS, ERR_R_ASN1_LIB); ECerr(EC_F_EC_GROUP_GET_ECPARAMETERS, ERR_R_ASN1_LIB);
goto err; goto err;
} }
...@@ -505,8 +507,9 @@ ECPARAMETERS *EC_GROUP_get_ecparameters(const EC_GROUP *group, ...@@ -505,8 +507,9 @@ ECPARAMETERS *EC_GROUP_get_ecparameters(const EC_GROUP *group,
/* set the cofactor (optional) */ /* set the cofactor (optional) */
tmp = EC_GROUP_get0_cofactor(group); tmp = EC_GROUP_get0_cofactor(group);
if (tmp != NULL) { if (tmp != NULL) {
ret->cofactor = BN_to_ASN1_INTEGER(tmp, ret->cofactor); ret->cofactor = BN_to_ASN1_INTEGER(tmp, orig = ret->cofactor);
if (ret->cofactor == NULL) { if (ret->cofactor == NULL) {
ret->cofactor = orig;
ECerr(EC_F_EC_GROUP_GET_ECPARAMETERS, ERR_R_ASN1_LIB); ECerr(EC_F_EC_GROUP_GET_ECPARAMETERS, ERR_R_ASN1_LIB);
goto err; goto err;
} }
......
...@@ -256,6 +256,7 @@ static int extract_min_max(ASIdOrRange *aor, ...@@ -256,6 +256,7 @@ static int extract_min_max(ASIdOrRange *aor,
static int ASIdentifierChoice_is_canonical(ASIdentifierChoice *choice) static int ASIdentifierChoice_is_canonical(ASIdentifierChoice *choice)
{ {
ASN1_INTEGER *a_max_plus_one = NULL; ASN1_INTEGER *a_max_plus_one = NULL;
ASN1_INTEGER *orig;
BIGNUM *bn = NULL; BIGNUM *bn = NULL;
int i, ret = 0; int i, ret = 0;
...@@ -298,9 +299,15 @@ static int ASIdentifierChoice_is_canonical(ASIdentifierChoice *choice) ...@@ -298,9 +299,15 @@ static int ASIdentifierChoice_is_canonical(ASIdentifierChoice *choice)
*/ */
if ((bn == NULL && (bn = BN_new()) == NULL) || if ((bn == NULL && (bn = BN_new()) == NULL) ||
ASN1_INTEGER_to_BN(a_max, bn) == NULL || ASN1_INTEGER_to_BN(a_max, bn) == NULL ||
!BN_add_word(bn, 1) || !BN_add_word(bn, 1)) {
(a_max_plus_one = X509V3err(X509V3_F_ASIDENTIFIERCHOICE_IS_CANONICAL,
BN_to_ASN1_INTEGER(bn, a_max_plus_one)) == NULL) { ERR_R_MALLOC_FAILURE);
goto done;
}
if ((a_max_plus_one =
BN_to_ASN1_INTEGER(bn, orig = a_max_plus_one)) == NULL) {
a_max_plus_one = orig;
X509V3err(X509V3_F_ASIDENTIFIERCHOICE_IS_CANONICAL, X509V3err(X509V3_F_ASIDENTIFIERCHOICE_IS_CANONICAL,
ERR_R_MALLOC_FAILURE); ERR_R_MALLOC_FAILURE);
goto done; goto done;
...@@ -351,6 +358,7 @@ int X509v3_asid_is_canonical(ASIdentifiers *asid) ...@@ -351,6 +358,7 @@ int X509v3_asid_is_canonical(ASIdentifiers *asid)
static int ASIdentifierChoice_canonize(ASIdentifierChoice *choice) static int ASIdentifierChoice_canonize(ASIdentifierChoice *choice)
{ {
ASN1_INTEGER *a_max_plus_one = NULL; ASN1_INTEGER *a_max_plus_one = NULL;
ASN1_INTEGER *orig;
BIGNUM *bn = NULL; BIGNUM *bn = NULL;
int i, ret = 0; int i, ret = 0;
...@@ -416,9 +424,15 @@ static int ASIdentifierChoice_canonize(ASIdentifierChoice *choice) ...@@ -416,9 +424,15 @@ static int ASIdentifierChoice_canonize(ASIdentifierChoice *choice)
*/ */
if ((bn == NULL && (bn = BN_new()) == NULL) || if ((bn == NULL && (bn = BN_new()) == NULL) ||
ASN1_INTEGER_to_BN(a_max, bn) == NULL || ASN1_INTEGER_to_BN(a_max, bn) == NULL ||
!BN_add_word(bn, 1) || !BN_add_word(bn, 1)) {
(a_max_plus_one = X509V3err(X509V3_F_ASIDENTIFIERCHOICE_CANONIZE,
BN_to_ASN1_INTEGER(bn, a_max_plus_one)) == NULL) { ERR_R_MALLOC_FAILURE);
goto done;
}
if ((a_max_plus_one =
BN_to_ASN1_INTEGER(bn, orig = a_max_plus_one)) == NULL) {
a_max_plus_one = orig;
X509V3err(X509V3_F_ASIDENTIFIERCHOICE_CANONIZE, X509V3err(X509V3_F_ASIDENTIFIERCHOICE_CANONIZE,
ERR_R_MALLOC_FAILURE); ERR_R_MALLOC_FAILURE);
goto done; goto done;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册