diff options
author | miod <> | 2015-07-19 05:42:55 +0000 |
---|---|---|
committer | miod <> | 2015-07-19 05:42:55 +0000 |
commit | e2fdff6ec8caaf7f2ab38d837f605b9724bc5279 (patch) | |
tree | 50a9d501470e88dcc8bed9bf14a1c0a28f099e3b | |
parent | bac793e50611d30da720c67ccfadbbf60bb3e8aa (diff) | |
download | openbsd-e2fdff6ec8caaf7f2ab38d837f605b9724bc5279.tar.gz openbsd-e2fdff6ec8caaf7f2ab38d837f605b9724bc5279.tar.bz2 openbsd-e2fdff6ec8caaf7f2ab38d837f605b9724bc5279.zip |
Now that it is safe to invoke X509_STORE_CTX_cleanup() if X509_STORE_CTX_init()
fails, check its return value and correctly mop up after ourselves.
ok beck@ doug@
-rw-r--r-- | src/lib/libcrypto/ts/ts_rsp_verify.c | 16 | ||||
-rw-r--r-- | src/lib/libcrypto/x509/x509_vfy.c | 8 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/ts/ts_rsp_verify.c | 16 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/x509/x509_vfy.c | 8 |
4 files changed, 32 insertions, 16 deletions
diff --git a/src/lib/libcrypto/ts/ts_rsp_verify.c b/src/lib/libcrypto/ts/ts_rsp_verify.c index 25aa31ee4d..797877011c 100644 --- a/src/lib/libcrypto/ts/ts_rsp_verify.c +++ b/src/lib/libcrypto/ts/ts_rsp_verify.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ts_rsp_verify.c,v 1.14 2015/07/19 02:43:24 miod Exp $ */ | 1 | /* $OpenBSD: ts_rsp_verify.c,v 1.15 2015/07/19 05:42:55 miod Exp $ */ |
2 | /* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL | 2 | /* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL |
3 | * project 2002. | 3 | * project 2002. |
4 | */ | 4 | */ |
@@ -234,26 +234,32 @@ static int | |||
234 | TS_verify_cert(X509_STORE *store, STACK_OF(X509) *untrusted, X509 *signer, | 234 | TS_verify_cert(X509_STORE *store, STACK_OF(X509) *untrusted, X509 *signer, |
235 | STACK_OF(X509) **chain) | 235 | STACK_OF(X509) **chain) |
236 | { | 236 | { |
237 | X509_STORE_CTX cert_ctx; | 237 | X509_STORE_CTX cert_ctx; |
238 | int i; | 238 | int i; |
239 | int ret = 1; | 239 | int ret = 0; |
240 | 240 | ||
241 | /* chain is an out argument. */ | 241 | /* chain is an out argument. */ |
242 | *chain = NULL; | 242 | *chain = NULL; |
243 | X509_STORE_CTX_init(&cert_ctx, store, signer, untrusted); | 243 | if (X509_STORE_CTX_init(&cert_ctx, store, signer, untrusted) == 0) { |
244 | TSerr(TS_F_TS_VERIFY_CERT, ERR_R_X509_LIB); | ||
245 | goto err; | ||
246 | } | ||
244 | X509_STORE_CTX_set_purpose(&cert_ctx, X509_PURPOSE_TIMESTAMP_SIGN); | 247 | X509_STORE_CTX_set_purpose(&cert_ctx, X509_PURPOSE_TIMESTAMP_SIGN); |
245 | i = X509_verify_cert(&cert_ctx); | 248 | i = X509_verify_cert(&cert_ctx); |
246 | if (i <= 0) { | 249 | if (i <= 0) { |
247 | int j = X509_STORE_CTX_get_error(&cert_ctx); | 250 | int j = X509_STORE_CTX_get_error(&cert_ctx); |
251 | |||
248 | TSerr(TS_F_TS_VERIFY_CERT, TS_R_CERTIFICATE_VERIFY_ERROR); | 252 | TSerr(TS_F_TS_VERIFY_CERT, TS_R_CERTIFICATE_VERIFY_ERROR); |
249 | ERR_asprintf_error_data("Verify error:%s", | 253 | ERR_asprintf_error_data("Verify error:%s", |
250 | X509_verify_cert_error_string(j)); | 254 | X509_verify_cert_error_string(j)); |
251 | ret = 0; | 255 | goto err; |
252 | } else { | 256 | } else { |
253 | /* Get a copy of the certificate chain. */ | 257 | /* Get a copy of the certificate chain. */ |
254 | *chain = X509_STORE_CTX_get1_chain(&cert_ctx); | 258 | *chain = X509_STORE_CTX_get1_chain(&cert_ctx); |
259 | ret = 1; | ||
255 | } | 260 | } |
256 | 261 | ||
262 | err: | ||
257 | X509_STORE_CTX_cleanup(&cert_ctx); | 263 | X509_STORE_CTX_cleanup(&cert_ctx); |
258 | 264 | ||
259 | return ret; | 265 | return ret; |
diff --git a/src/lib/libcrypto/x509/x509_vfy.c b/src/lib/libcrypto/x509/x509_vfy.c index bc5905784d..f2dc356dc8 100644 --- a/src/lib/libcrypto/x509/x509_vfy.c +++ b/src/lib/libcrypto/x509/x509_vfy.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: x509_vfy.c,v 1.43 2015/07/19 01:44:16 doug Exp $ */ | 1 | /* $OpenBSD: x509_vfy.c,v 1.44 2015/07/19 05:42:55 miod Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -1091,8 +1091,10 @@ check_crl_path(X509_STORE_CTX *ctx, X509 *x) | |||
1091 | /* Don't allow recursive CRL path validation */ | 1091 | /* Don't allow recursive CRL path validation */ |
1092 | if (ctx->parent) | 1092 | if (ctx->parent) |
1093 | return 0; | 1093 | return 0; |
1094 | if (!X509_STORE_CTX_init(&crl_ctx, ctx->ctx, x, ctx->untrusted)) | 1094 | if (!X509_STORE_CTX_init(&crl_ctx, ctx->ctx, x, ctx->untrusted)) { |
1095 | return -1; | 1095 | ret = -1; |
1096 | goto err; | ||
1097 | } | ||
1096 | 1098 | ||
1097 | crl_ctx.crls = ctx->crls; | 1099 | crl_ctx.crls = ctx->crls; |
1098 | /* Copy verify params across */ | 1100 | /* Copy verify params across */ |
diff --git a/src/lib/libssl/src/crypto/ts/ts_rsp_verify.c b/src/lib/libssl/src/crypto/ts/ts_rsp_verify.c index 25aa31ee4d..797877011c 100644 --- a/src/lib/libssl/src/crypto/ts/ts_rsp_verify.c +++ b/src/lib/libssl/src/crypto/ts/ts_rsp_verify.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ts_rsp_verify.c,v 1.14 2015/07/19 02:43:24 miod Exp $ */ | 1 | /* $OpenBSD: ts_rsp_verify.c,v 1.15 2015/07/19 05:42:55 miod Exp $ */ |
2 | /* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL | 2 | /* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL |
3 | * project 2002. | 3 | * project 2002. |
4 | */ | 4 | */ |
@@ -234,26 +234,32 @@ static int | |||
234 | TS_verify_cert(X509_STORE *store, STACK_OF(X509) *untrusted, X509 *signer, | 234 | TS_verify_cert(X509_STORE *store, STACK_OF(X509) *untrusted, X509 *signer, |
235 | STACK_OF(X509) **chain) | 235 | STACK_OF(X509) **chain) |
236 | { | 236 | { |
237 | X509_STORE_CTX cert_ctx; | 237 | X509_STORE_CTX cert_ctx; |
238 | int i; | 238 | int i; |
239 | int ret = 1; | 239 | int ret = 0; |
240 | 240 | ||
241 | /* chain is an out argument. */ | 241 | /* chain is an out argument. */ |
242 | *chain = NULL; | 242 | *chain = NULL; |
243 | X509_STORE_CTX_init(&cert_ctx, store, signer, untrusted); | 243 | if (X509_STORE_CTX_init(&cert_ctx, store, signer, untrusted) == 0) { |
244 | TSerr(TS_F_TS_VERIFY_CERT, ERR_R_X509_LIB); | ||
245 | goto err; | ||
246 | } | ||
244 | X509_STORE_CTX_set_purpose(&cert_ctx, X509_PURPOSE_TIMESTAMP_SIGN); | 247 | X509_STORE_CTX_set_purpose(&cert_ctx, X509_PURPOSE_TIMESTAMP_SIGN); |
245 | i = X509_verify_cert(&cert_ctx); | 248 | i = X509_verify_cert(&cert_ctx); |
246 | if (i <= 0) { | 249 | if (i <= 0) { |
247 | int j = X509_STORE_CTX_get_error(&cert_ctx); | 250 | int j = X509_STORE_CTX_get_error(&cert_ctx); |
251 | |||
248 | TSerr(TS_F_TS_VERIFY_CERT, TS_R_CERTIFICATE_VERIFY_ERROR); | 252 | TSerr(TS_F_TS_VERIFY_CERT, TS_R_CERTIFICATE_VERIFY_ERROR); |
249 | ERR_asprintf_error_data("Verify error:%s", | 253 | ERR_asprintf_error_data("Verify error:%s", |
250 | X509_verify_cert_error_string(j)); | 254 | X509_verify_cert_error_string(j)); |
251 | ret = 0; | 255 | goto err; |
252 | } else { | 256 | } else { |
253 | /* Get a copy of the certificate chain. */ | 257 | /* Get a copy of the certificate chain. */ |
254 | *chain = X509_STORE_CTX_get1_chain(&cert_ctx); | 258 | *chain = X509_STORE_CTX_get1_chain(&cert_ctx); |
259 | ret = 1; | ||
255 | } | 260 | } |
256 | 261 | ||
262 | err: | ||
257 | X509_STORE_CTX_cleanup(&cert_ctx); | 263 | X509_STORE_CTX_cleanup(&cert_ctx); |
258 | 264 | ||
259 | return ret; | 265 | return ret; |
diff --git a/src/lib/libssl/src/crypto/x509/x509_vfy.c b/src/lib/libssl/src/crypto/x509/x509_vfy.c index bc5905784d..f2dc356dc8 100644 --- a/src/lib/libssl/src/crypto/x509/x509_vfy.c +++ b/src/lib/libssl/src/crypto/x509/x509_vfy.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: x509_vfy.c,v 1.43 2015/07/19 01:44:16 doug Exp $ */ | 1 | /* $OpenBSD: x509_vfy.c,v 1.44 2015/07/19 05:42:55 miod Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -1091,8 +1091,10 @@ check_crl_path(X509_STORE_CTX *ctx, X509 *x) | |||
1091 | /* Don't allow recursive CRL path validation */ | 1091 | /* Don't allow recursive CRL path validation */ |
1092 | if (ctx->parent) | 1092 | if (ctx->parent) |
1093 | return 0; | 1093 | return 0; |
1094 | if (!X509_STORE_CTX_init(&crl_ctx, ctx->ctx, x, ctx->untrusted)) | 1094 | if (!X509_STORE_CTX_init(&crl_ctx, ctx->ctx, x, ctx->untrusted)) { |
1095 | return -1; | 1095 | ret = -1; |
1096 | goto err; | ||
1097 | } | ||
1096 | 1098 | ||
1097 | crl_ctx.crls = ctx->crls; | 1099 | crl_ctx.crls = ctx->crls; |
1098 | /* Copy verify params across */ | 1100 | /* Copy verify params across */ |