Skip to content

Commit

Permalink
x509_vfy: remove redundant stack allocation
Browse files Browse the repository at this point in the history
Fix CID 1472833 by removing a codepath that attempts to allocate a
stack if not already allocated, when the stack was already allocated
unconditionally a few lines previously.

Interestingly enough, this additional allocation path (and the comment
describing the need for it) were added in commit
69664d6, also prompted by Coverity(!).
It seems that the intervening (and much more recent) commit
d53b437 that allowed sk_X509_dup()
to accept a NULL argument allowed the earlier initialization path
to unconditionally allocate a stack, rendering this later allocation fully
redundant.
  • Loading branch information
kaduk committed Feb 12, 2021
1 parent 22040fb commit a5076aa
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions crypto/x509/x509_vfy.c
Expand Up @@ -3033,17 +3033,9 @@ static int build_chain(X509_STORE_CTX *ctx)

/*
* If we got any "DANE-TA(2) Cert(0) Full(0)" trust anchors from DNS, add
* them to our working copy of the untrusted certificate stack. Since the
* caller of X509_STORE_CTX_init() may have provided only a leaf cert with
* no corresponding stack of untrusted certificates, we may need to create
* an empty stack first. [ At present only the ssl library provides DANE
* support, and ssl_verify_cert_chain() always provides a non-null stack
* containing at least the leaf certificate, but we must be prepared for
* this to change. ]
* them to our working copy of the untrusted certificate stack.
*/
if (DANETLS_ENABLED(dane) && dane->certs != NULL) {
if (sk_untrusted == NULL && (sk_untrusted = sk_X509_new_null()) == NULL)
goto memerr;
if (!X509_add_certs(sk_untrusted, dane->certs, X509_ADD_FLAG_DEFAULT)) {
sk_X509_free(sk_untrusted);
goto memerr;
Expand Down

0 comments on commit a5076aa

Please sign in to comment.