Skip to content

Commit 8da4983

Browse files
davidbenevanlucas
authored andcommitted
crypto: use X509_STORE_CTX_new
In OpenSSL 1.1.0, X509_STORE_CTX is opaque and thus cannot be stack-allocated. This works in OpenSSL 1.1.0 and 1.0.2. Adapted from PR PR-URL: #16130 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Rod Vagg <[email protected]>
1 parent b42013c commit 8da4983

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

src/node_crypto.cc

+5-12
Original file line numberDiff line numberDiff line change
@@ -572,19 +572,12 @@ void SecureContext::SetKey(const FunctionCallbackInfo<Value>& args) {
572572

573573

574574
int SSL_CTX_get_issuer(SSL_CTX* ctx, X509* cert, X509** issuer) {
575-
int ret;
576-
577575
X509_STORE* store = SSL_CTX_get_cert_store(ctx);
578-
X509_STORE_CTX store_ctx;
579-
580-
ret = X509_STORE_CTX_init(&store_ctx, store, nullptr, nullptr);
581-
if (!ret)
582-
goto end;
583-
584-
ret = X509_STORE_CTX_get1_issuer(issuer, &store_ctx, cert);
585-
X509_STORE_CTX_cleanup(&store_ctx);
586-
587-
end:
576+
X509_STORE_CTX* store_ctx = X509_STORE_CTX_new();
577+
int ret = store_ctx != nullptr &&
578+
X509_STORE_CTX_init(store_ctx, store, nullptr, nullptr) == 1 &&
579+
X509_STORE_CTX_get1_issuer(issuer, store_ctx, cert) == 1;
580+
X509_STORE_CTX_free(store_ctx);
588581
return ret;
589582
}
590583

0 commit comments

Comments
 (0)