提交 1687aa76 编写于 作者: F FdaSilvaYY 提交者: Andy Polyakov

Fix possible leaks on sk_X509_EXTENSION_push() failure ...

Reviewed-by: NRich Salz <rsalz@openssl.org>
Reviewed-by: NAndy Polyakov <appro@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/4677)
上级 1097d2a3
...@@ -54,6 +54,7 @@ const X509V3_EXT_METHOD *X509V3_EXT_get_nid(int nid) ...@@ -54,6 +54,7 @@ const X509V3_EXT_METHOD *X509V3_EXT_get_nid(int nid)
X509V3_EXT_METHOD tmp; X509V3_EXT_METHOD tmp;
const X509V3_EXT_METHOD *t = &tmp, *const *ret; const X509V3_EXT_METHOD *t = &tmp, *const *ret;
int idx; int idx;
if (nid < 0) if (nid < 0)
return NULL; return NULL;
tmp.ext_nid = nid; tmp.ext_nid = nid;
...@@ -165,6 +166,7 @@ void *X509V3_get_d2i(const STACK_OF(X509_EXTENSION) *x, int nid, int *crit, ...@@ -165,6 +166,7 @@ void *X509V3_get_d2i(const STACK_OF(X509_EXTENSION) *x, int nid, int *crit,
{ {
int lastpos, i; int lastpos, i;
X509_EXTENSION *ex, *found_ex = NULL; X509_EXTENSION *ex, *found_ex = NULL;
if (!x) { if (!x) {
if (idx) if (idx)
*idx = -1; *idx = -1;
...@@ -218,9 +220,9 @@ void *X509V3_get_d2i(const STACK_OF(X509_EXTENSION) *x, int nid, int *crit, ...@@ -218,9 +220,9 @@ void *X509V3_get_d2i(const STACK_OF(X509_EXTENSION) *x, int nid, int *crit,
int X509V3_add1_i2d(STACK_OF(X509_EXTENSION) **x, int nid, void *value, int X509V3_add1_i2d(STACK_OF(X509_EXTENSION) **x, int nid, void *value,
int crit, unsigned long flags) int crit, unsigned long flags)
{ {
int extidx = -1; int errcode, extidx = -1;
int errcode; X509_EXTENSION *ext = NULL, *extmp;
X509_EXTENSION *ext, *extmp; STACK_OF(X509_EXTENSION) *ret = NULL;
unsigned long ext_op = flags & X509V3_ADD_OP_MASK; unsigned long ext_op = flags & X509V3_ADD_OP_MASK;
/* /*
...@@ -279,14 +281,23 @@ int X509V3_add1_i2d(STACK_OF(X509_EXTENSION) **x, int nid, void *value, ...@@ -279,14 +281,23 @@ int X509V3_add1_i2d(STACK_OF(X509_EXTENSION) **x, int nid, void *value,
return 1; return 1;
} }
ret = *x;
if (*x == NULL if (*x == NULL
&& (*x = sk_X509_EXTENSION_new_null()) == NULL) && (ret = sk_X509_EXTENSION_new_null()) == NULL)
return -1; goto m_fail;
if (!sk_X509_EXTENSION_push(*x, ext)) if (!sk_X509_EXTENSION_push(ret, ext))
return -1; goto m_fail;
*x = ret;
return 1; return 1;
m_fail:
/* X509V3err(X509V3_F_X509V3_ADD1_I2D, ERR_R_MALLOC_FAILURE); */
if (ret != *x)
sk_X509_EXTENSION_free(ret);
X509_EXTENSION_free(ext);
return -1;
err: err:
if (!(flags & X509V3_ADD_SILENT)) if (!(flags & X509V3_ADD_SILENT))
X509V3err(X509V3_F_X509V3_ADD1_I2D, errcode); X509V3err(X509V3_F_X509V3_ADD1_I2D, errcode);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册