Skip to content

Commit f507297

Browse files
davidbenjustsmth
authored andcommitted
Remove X509_STORE_CTX_zero
This was never used externally. It's a remnant of when we supported stack-allocated X509_STOREs, but now its opaque. Change-Id: Idb997237ca81f4c35795cfc8c9d2ee222629e1ce Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/64128 Auto-Submit: David Benjamin <[email protected]> Reviewed-by: Bob Beck <[email protected]> Commit-Queue: Bob Beck <[email protected]> (cherry picked from commit 698aa894c96412d4df20e2bb031d9eb9c9d5919a)
1 parent 49e96b1 commit f507297

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

crypto/x509/x509_vfy.c

+8-13
Original file line numberDiff line numberDiff line change
@@ -1659,18 +1659,7 @@ int X509_STORE_CTX_purpose_inherit(X509_STORE_CTX *ctx, int def_purpose,
16591659
}
16601660

16611661
X509_STORE_CTX *X509_STORE_CTX_new(void) {
1662-
X509_STORE_CTX *ctx;
1663-
ctx = (X509_STORE_CTX *)OPENSSL_zalloc(sizeof(X509_STORE_CTX));
1664-
if (!ctx) {
1665-
return NULL;
1666-
}
1667-
// NO-OP: struct already zeroed
1668-
//X509_STORE_CTX_zero(ctx);
1669-
return ctx;
1670-
}
1671-
1672-
void X509_STORE_CTX_zero(X509_STORE_CTX *ctx) {
1673-
OPENSSL_memset(ctx, 0, sizeof(X509_STORE_CTX));
1662+
return OPENSSL_zalloc(sizeof(X509_STORE_CTX));
16741663
}
16751664

16761665
void X509_STORE_CTX_free(X509_STORE_CTX *ctx) {
@@ -1683,7 +1672,13 @@ void X509_STORE_CTX_free(X509_STORE_CTX *ctx) {
16831672

16841673
int X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, X509 *x509,
16851674
STACK_OF(X509) *chain) {
1686-
X509_STORE_CTX_zero(ctx);
1675+
// TODO(davidben): This is a remnant of when |X509_STORE_CTX| was a
1676+
// stack-allocatable function. Now that it is heap-allocated, we don't need to
1677+
// worry about uninitialized memory in |ctx|. Move the memset to
1678+
// |X509_STORE_CTX_cleanup| and call |X509_STORE_CTX_cleanup| here so callers
1679+
// don't leak memory when re-initializing a previously initialized
1680+
// |X509_STORE_CTX|.
1681+
OPENSSL_memset(ctx, 0, sizeof(X509_STORE_CTX));
16871682
ctx->ctx = store;
16881683
ctx->cert = x509;
16891684
ctx->untrusted = chain;

include/openssl/x509.h

-1
Original file line numberDiff line numberDiff line change
@@ -3118,7 +3118,6 @@ OPENSSL_EXPORT X509_STORE_CTX *X509_STORE_CTX_new(void);
31183118
OPENSSL_EXPORT int X509_STORE_CTX_get1_issuer(X509 **issuer,
31193119
X509_STORE_CTX *ctx, X509 *x);
31203120

3121-
OPENSSL_EXPORT void X509_STORE_CTX_zero(X509_STORE_CTX *ctx);
31223121
OPENSSL_EXPORT void X509_STORE_CTX_free(X509_STORE_CTX *ctx);
31233122
OPENSSL_EXPORT int X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store,
31243123
X509 *x509, STACK_OF(X509) *chain);

0 commit comments

Comments
 (0)