/*
- * Copyright 1999-2021 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 1999-2022 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
/* X509 v3 extension utilities */
-#include "e_os.h"
+#include "internal/e_os.h"
#include "internal/cryptlib.h"
#include <stdio.h>
#include <string.h>
}
if ((vtmp = OPENSSL_malloc(sizeof(*vtmp))) == NULL)
goto err;
- if (sk_allocated && (*extlist = sk_CONF_VALUE_new_null()) == NULL)
+ if (sk_allocated && (*extlist = sk_CONF_VALUE_new_null()) == NULL) {
+ ERR_raise(ERR_LIB_X509V3, ERR_R_CRYPTO_LIB);
goto err;
+ }
vtmp->section = NULL;
vtmp->name = tname;
vtmp->value = tvalue;
goto err;
return 1;
err:
- ERR_raise(ERR_LIB_X509V3, ERR_R_MALLOC_FAILURE);
if (sk_allocated) {
sk_CONF_VALUE_free(*extlist);
*extlist = NULL;
len = strlen(tmp) + 3;
ret = OPENSSL_malloc(len);
if (ret == NULL) {
- ERR_raise(ERR_LIB_X509V3, ERR_R_MALLOC_FAILURE);
OPENSSL_free(tmp);
return NULL;
}
if (!a)
return NULL;
- if ((bntmp = ASN1_ENUMERATED_to_BN(a, NULL)) == NULL
- || (strtmp = bignum_to_string(bntmp)) == NULL)
- ERR_raise(ERR_LIB_X509V3, ERR_R_MALLOC_FAILURE);
+ if ((bntmp = ASN1_ENUMERATED_to_BN(a, NULL)) == NULL)
+ ERR_raise(ERR_LIB_X509V3, ERR_R_ASN1_LIB);
+ else if ((strtmp = bignum_to_string(bntmp)) == NULL)
+ ERR_raise(ERR_LIB_X509V3, ERR_R_X509V3_LIB);
BN_free(bntmp);
return strtmp;
}
if (!a)
return NULL;
- if ((bntmp = ASN1_INTEGER_to_BN(a, NULL)) == NULL
- || (strtmp = bignum_to_string(bntmp)) == NULL)
- ERR_raise(ERR_LIB_X509V3, ERR_R_MALLOC_FAILURE);
+ if ((bntmp = ASN1_INTEGER_to_BN(a, NULL)) == NULL)
+ ERR_raise(ERR_LIB_X509V3, ERR_R_ASN1_LIB);
+ else if ((strtmp = bignum_to_string(bntmp)) == NULL)
+ ERR_raise(ERR_LIB_X509V3, ERR_R_X509V3_LIB);
BN_free(bntmp);
return strtmp;
}
}
bn = BN_new();
if (bn == NULL) {
- ERR_raise(ERR_LIB_X509V3, ERR_R_MALLOC_FAILURE);
+ ERR_raise(ERR_LIB_X509V3, ERR_R_BN_LIB);
return NULL;
}
if (value[0] == '-') {
/* We are going to modify the line so copy it first */
linebuf = OPENSSL_strdup(line);
- if (linebuf == NULL) {
- ERR_raise(ERR_LIB_X509V3, ERR_R_MALLOC_FAILURE);
+ if (linebuf == NULL)
goto err;
- }
state = HDR_NAME;
ntmp = NULL;
/* Go through all characters */
ERR_raise(ERR_LIB_X509V3, X509V3_R_INVALID_EMPTY_NAME);
goto err;
}
- X509V3_add_value(ntmp, NULL, &values);
+ if (!X509V3_add_value(ntmp, NULL, &values)) {
+ goto err;
+ }
}
break;
ERR_raise(ERR_LIB_X509V3, X509V3_R_INVALID_NULL_VALUE);
goto err;
}
- X509V3_add_value(ntmp, vtmp, &values);
+ if (!X509V3_add_value(ntmp, vtmp, &values)) {
+ goto err;
+ }
ntmp = NULL;
q = p + 1;
}
ERR_raise(ERR_LIB_X509V3, X509V3_R_INVALID_NULL_VALUE);
goto err;
}
- X509V3_add_value(ntmp, vtmp, &values);
+ if (!X509V3_add_value(ntmp, vtmp, &values)) {
+ goto err;
+ }
} else {
ntmp = strip_spaces(q);
if (!ntmp) {
ERR_raise(ERR_LIB_X509V3, X509V3_R_INVALID_EMPTY_NAME);
goto err;
}
- X509V3_add_value(ntmp, NULL, &values);
+ if (!X509V3_add_value(ntmp, NULL, &values)) {
+ goto err;
+ }
}
OPENSSL_free(linebuf);
return values;
return 0;
emtmp = OPENSSL_strndup((char *)email->data, email->length);
- if (emtmp == NULL)
+ if (emtmp == NULL) {
+ X509_email_free(*sk);
+ *sk = NULL;
return 0;
+ }
/* Don't add duplicates */
if (sk_OPENSSL_STRING_find(*sk, emtmp) != -1) {
rv = equal(a->data, a->length, (unsigned char *)b, blen, flags);
else if (a->length == (int)blen && !memcmp(a->data, b, blen))
rv = 1;
- if (rv > 0 && peername)
+ if (rv > 0 && peername != NULL) {
*peername = OPENSSL_strndup((char *)a->data, a->length);
+ if (*peername == NULL)
+ return -1;
+ }
} else {
int astrlen;
unsigned char *astr;
return -1;
}
rv = equal(astr, astrlen, (unsigned char *)b, blen, flags);
- if (rv > 0 && peername)
+ if (rv > 0 && peername != NULL) {
*peername = OPENSSL_strndup((char *)astr, astrlen);
+ if (*peername == NULL) {
+ OPENSSL_free(astr);
+ return -1;
+ }
+ }
OPENSSL_free(astr);
}
return rv;