Merge pull request #6313 from anhu/empty_stack

Should not be an error to call wolfSSL_X509_REQ_add_extensions with...
This commit is contained in:
JacobBarthelmeh 2023-04-19 10:32:06 -06:00 committed by GitHub
commit 0186fb7114
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -13618,13 +13618,21 @@ static int regenX509REQDerBuffer(WOLFSSL_X509* x509)
int wolfSSL_X509_REQ_add_extensions(WOLFSSL_X509* req,
WOLF_STACK_OF(WOLFSSL_X509_EXTENSION)* ext_sk)
{
WOLFSSL_X509_EXTENSION* ext = NULL;
if (!req || !ext_sk) {
WOLFSSL_MSG("Bad parameter");
return WOLFSSL_FAILURE;
}
/* It is not an error if the stack is empty. */
ext = ext_sk->data.ext;
if (ext == NULL) {
return WOLFSSL_SUCCESS;
}
while (ext_sk) {
WOLFSSL_X509_EXTENSION* ext = ext_sk->data.ext;
ext = ext_sk->data.ext;
if (wolfSSL_X509_add_ext(req, ext, -1) != WOLFSSL_SUCCESS) {
WOLFSSL_MSG("wolfSSL_X509_add_ext error");

View File

@ -43377,6 +43377,8 @@ static int test_othername_and_SID_ext(void) {
AssertNotNull(sid_ext = X509_EXTENSION_create_by_OBJ(NULL, sid_oid, 0,
sid_data));
AssertNotNull(exts = sk_X509_EXTENSION_new_null());
/* Ensure an empty stack doesn't raise an error. */
AssertIntEQ(X509_REQ_add_extensions(x509, exts), 1);
AssertIntEQ(sk_X509_EXTENSION_push(exts, san_ext), 1);
AssertIntEQ(sk_X509_EXTENSION_push(exts, sid_ext), 2);
AssertIntEQ(X509_REQ_add_extensions(x509, exts), 1);