Skip to content

Commit f26d468

Browse files
Protect against exceeding original depth, fix overlong lines.
1 parent 785f9b0 commit f26d468

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

src/ssl.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6100,7 +6100,8 @@ int AddCA(WOLFSSL_CERT_MANAGER* cm, DerBuffer** pDer, int type, int verify)
61006100
return ret == 0 ? WOLFSSL_SUCCESS : ret;
61016101
}
61026102

6103-
/* Removes the CA with the passed in subject hash from the cert manager's CA cert store. */
6103+
/* Removes the CA with the passed in subject hash from the
6104+
cert manager's CA cert store. */
61046105
int RemoveCA(WOLFSSL_CERT_MANAGER* cm, byte* hash, int type)
61056106
{
61066107
Signer* current;

src/x509_str.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
#ifdef OPENSSL_EXTRA
3535
static int X509StoreGetIssuerEx(WOLFSSL_X509 **issuer,
3636
WOLFSSL_STACK *certs, WOLFSSL_X509 *x);
37-
static int X509StorePopCert(WOLFSSL_STACK *certs_stack, WOLFSSL_STACK *dest_stack,
37+
static int X509StorePopCert(WOLFSSL_STACK *certs_stack,
38+
WOLFSSL_STACK *dest_stack,
3839
WOLFSSL_X509 *cert);
3940
static int X509StoreAddCa(WOLFSSL_X509_STORE* store,
4041
WOLFSSL_X509* x509, int type);
@@ -566,14 +567,17 @@ int wolfSSL_X509_verify_cert(WOLFSSL_X509_STORE_CTX* ctx)
566567
continue;
567568

568569
retry:
569-
/* Current certificate failed, but it is possible there is an alternative
570-
* cert with the same subject key which will work. Retry until all
571-
* possible candidate certs are exhausted. */
572-
WOLFSSL_MSG("X509_verify_cert current cert failed, retrying with other certs.");
573-
ret = X509StoreRemoveCa(ctx->store, ctx->current_cert, WOLFSSL_TEMP_CA);
570+
/* Current certificate failed, but it is possible there is an
571+
* alternative cert with the same subject key which will work.
572+
* Retry until all possible candidate certs are exhausted. */
573+
WOLFSSL_MSG("X509_verify_cert current cert failed,"
574+
"retrying with other certs.");
575+
ret = X509StoreRemoveCa(ctx->store, ctx->current_cert,
576+
WOLFSSL_TEMP_CA);
574577
X509StorePopCert(certs, failedCerts, ctx->current_cert);
575578
ctx->current_cert = wolfSSL_sk_X509_pop(ctx->chain);
576-
depth++;
579+
if (depth < origDepth)
580+
depth++;
577581
}
578582

579583
exit:
@@ -1094,15 +1098,18 @@ static int X509StoreGetIssuerEx(WOLFSSL_X509 **issuer,
10941098
return WOLFSSL_FAILURE;
10951099
}
10961100

1097-
static int X509StorePopCert(WOLFSSL_STACK *certs_stack, WOLFSSL_STACK *dest_stack, WOLFSSL_X509 *cert) {
1101+
static int X509StorePopCert(WOLFSSL_STACK *certs_stack,
1102+
WOLFSSL_STACK *dest_stack,
1103+
WOLFSSL_X509 *cert) {
10981104
int i;
10991105

11001106
if (certs_stack == NULL || dest_stack == NULL || cert == NULL)
11011107
return WOLFSSL_FATAL_ERROR;
11021108

11031109
for (i = 0; i < wolfSSL_sk_X509_num(certs_stack); i++) {
11041110
if (wolfSSL_sk_X509_value(certs_stack, i) == cert) {
1105-
wolfSSL_sk_X509_push(dest_stack, (WOLFSSL_X509*)wolfSSL_sk_pop_node(certs_stack, i));
1111+
wolfSSL_sk_X509_push(dest_stack,
1112+
(WOLFSSL_X509*)wolfSSL_sk_pop_node(certs_stack, i));
11061113
return WOLFSSL_SUCCESS;
11071114
}
11081115
}
@@ -1456,7 +1463,8 @@ static int X509StoreRemoveCa(WOLFSSL_X509_STORE* store,
14561463
return result;
14571464
}
14581465
XMEMSET(dCert, 0, sizeof(DecodedCert));
1459-
wc_InitDecodedCert(dCert, x509->derCert->buffer, x509->derCert->length, NULL);
1466+
wc_InitDecodedCert(dCert, x509->derCert->buffer,
1467+
x509->derCert->length, NULL);
14601468
result = wc_ParseCert(dCert, CA_TYPE, NO_VERIFY, store->cm);
14611469
if (result)
14621470
return WOLFSSL_FATAL_ERROR;

0 commit comments

Comments
 (0)