aboutsummaryrefslogtreecommitdiff
path: root/crypto/x509v3/v3_cpols.c
diff options
context:
space:
mode:
authorFdaSilvaYY <fdasilvayy@gmail.com>2017-09-28 23:30:22 +0200
committerAndy Polyakov <appro@openssl.org>2017-10-03 12:52:19 +0200
commit270a4bba49849de7f928f4fab186205abd132411 (patch)
treee7687d33244805badcfb2892058851ed04927b21 /crypto/x509v3/v3_cpols.c
parent8e8e507ed720ca0acbeb15e238bf99519a9e7aab (diff)
downloadopenssl-270a4bba49849de7f928f4fab186205abd132411.zip
openssl-270a4bba49849de7f928f4fab186205abd132411.tar.gz
openssl-270a4bba49849de7f928f4fab186205abd132411.tar.bz2
Use more pre-allocation
Reviewed-by: Andy Polyakov <appro@openssl.org> Reviewed-by: Paul Dale <paul.dale@oracle.com> Reviewed-by: Richard Levitte <levitte@openssl.org> (Merged from https://github.com/openssl/openssl/pull/4379)
Diffstat (limited to 'crypto/x509v3/v3_cpols.c')
-rw-r--r--crypto/x509v3/v3_cpols.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/crypto/x509v3/v3_cpols.c b/crypto/x509v3/v3_cpols.c
index ea65e07..56460a3 100644
--- a/crypto/x509v3/v3_cpols.c
+++ b/crypto/x509v3/v3_cpols.c
@@ -88,26 +88,30 @@ IMPLEMENT_ASN1_FUNCTIONS(NOTICEREF)
static STACK_OF(POLICYINFO) *r2i_certpol(X509V3_EXT_METHOD *method,
X509V3_CTX *ctx, const char *value)
{
- STACK_OF(POLICYINFO) *pols = NULL;
+ STACK_OF(POLICYINFO) *pols;
char *pstr;
POLICYINFO *pol;
ASN1_OBJECT *pobj;
- STACK_OF(CONF_VALUE) *vals;
+ STACK_OF(CONF_VALUE) *vals = X509V3_parse_list(value);
CONF_VALUE *cnf;
+ const int num = sk_CONF_VALUE_num(vals);
int i, ia5org;
- pols = sk_POLICYINFO_new_null();
- if (pols == NULL) {
- X509V3err(X509V3_F_R2I_CERTPOL, ERR_R_MALLOC_FAILURE);
- return NULL;
- }
- vals = X509V3_parse_list(value);
+
if (vals == NULL) {
X509V3err(X509V3_F_R2I_CERTPOL, ERR_R_X509V3_LIB);
+ return NULL;
+ }
+
+ pols = sk_POLICYINFO_new_null();
+ if (pols == NULL || !sk_POLICYINFO_reserve(pols, num)) {
+ X509V3err(X509V3_F_R2I_CERTPOL, ERR_R_MALLOC_FAILURE);
goto err;
}
+
ia5org = 0;
- for (i = 0; i < sk_CONF_VALUE_num(vals); i++) {
+ for (i = 0; i < num; i++) {
cnf = sk_CONF_VALUE_value(vals, i);
+
if (cnf->value || !cnf->name) {
X509V3err(X509V3_F_R2I_CERTPOL,
X509V3_R_INVALID_POLICY_IDENTIFIER);
@@ -241,7 +245,6 @@ static POLICYINFO *policy_section(X509V3_CTX *ctx,
err:
POLICYINFO_free(pol);
return NULL;
-
}
static int displaytext_get_tag_len(const char *tagstr)