From 68a272ff45d44b26bcfbf7aac61d5a3b1746d781 Mon Sep 17 00:00:00 2001 From: miod Date: Sat, 12 Jul 2014 14:58:32 +0000 Subject: [PATCH] Principle of least surprise: make CMAC_CTX_free(), OCSP_REQ_CTX_free() and X509_STORE_CTX_free() accept NULL pointers as input without dereferencing them, like all the other well-behaved *_CTX_free() functions do. --- lib/libcrypto/cmac/cmac.c | 5 ++++- lib/libcrypto/ocsp/ocsp_ht.c | 5 ++++- lib/libcrypto/x509/x509_vfy.c | 5 ++++- lib/libssl/src/crypto/cmac/cmac.c | 5 ++++- lib/libssl/src/crypto/ocsp/ocsp_ht.c | 5 ++++- lib/libssl/src/crypto/x509/x509_vfy.c | 5 ++++- 6 files changed, 24 insertions(+), 6 deletions(-) diff --git a/lib/libcrypto/cmac/cmac.c b/lib/libcrypto/cmac/cmac.c index baba674ec1d..18635b942a8 100644 --- a/lib/libcrypto/cmac/cmac.c +++ b/lib/libcrypto/cmac/cmac.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmac.c,v 1.8 2014/07/11 08:44:48 jsing Exp $ */ +/* $OpenBSD: cmac.c,v 1.9 2014/07/12 14:58:32 miod Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project. */ @@ -123,6 +123,9 @@ CMAC_CTX_get0_cipher_ctx(CMAC_CTX *ctx) void CMAC_CTX_free(CMAC_CTX *ctx) { + if (ctx == NULL) + return; + CMAC_CTX_cleanup(ctx); free(ctx); } diff --git a/lib/libcrypto/ocsp/ocsp_ht.c b/lib/libcrypto/ocsp/ocsp_ht.c index bc3c957b0cb..c895e9df4db 100644 --- a/lib/libcrypto/ocsp/ocsp_ht.c +++ b/lib/libcrypto/ocsp/ocsp_ht.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ocsp_ht.c,v 1.19 2014/06/12 15:49:30 deraadt Exp $ */ +/* $OpenBSD: ocsp_ht.c,v 1.20 2014/07/12 14:58:32 miod Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 2006. */ @@ -108,6 +108,9 @@ static int parse_http_line1(char *line); void OCSP_REQ_CTX_free(OCSP_REQ_CTX *rctx) { + if (rctx == NULL) + return; + if (rctx->mem) BIO_free(rctx->mem); free(rctx->iobuf); diff --git a/lib/libcrypto/x509/x509_vfy.c b/lib/libcrypto/x509/x509_vfy.c index 9d7a7d12289..d894facd473 100644 --- a/lib/libcrypto/x509/x509_vfy.c +++ b/lib/libcrypto/x509/x509_vfy.c @@ -1,4 +1,4 @@ -/* $OpenBSD: x509_vfy.c,v 1.34 2014/07/11 12:52:41 miod Exp $ */ +/* $OpenBSD: x509_vfy.c,v 1.35 2014/07/12 14:58:32 miod Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -1979,6 +1979,9 @@ X509_STORE_CTX_new(void) void X509_STORE_CTX_free(X509_STORE_CTX *ctx) { + if (ctx == NULL) + return; + X509_STORE_CTX_cleanup(ctx); free(ctx); } diff --git a/lib/libssl/src/crypto/cmac/cmac.c b/lib/libssl/src/crypto/cmac/cmac.c index baba674ec1d..18635b942a8 100644 --- a/lib/libssl/src/crypto/cmac/cmac.c +++ b/lib/libssl/src/crypto/cmac/cmac.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmac.c,v 1.8 2014/07/11 08:44:48 jsing Exp $ */ +/* $OpenBSD: cmac.c,v 1.9 2014/07/12 14:58:32 miod Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project. */ @@ -123,6 +123,9 @@ CMAC_CTX_get0_cipher_ctx(CMAC_CTX *ctx) void CMAC_CTX_free(CMAC_CTX *ctx) { + if (ctx == NULL) + return; + CMAC_CTX_cleanup(ctx); free(ctx); } diff --git a/lib/libssl/src/crypto/ocsp/ocsp_ht.c b/lib/libssl/src/crypto/ocsp/ocsp_ht.c index bc3c957b0cb..c895e9df4db 100644 --- a/lib/libssl/src/crypto/ocsp/ocsp_ht.c +++ b/lib/libssl/src/crypto/ocsp/ocsp_ht.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ocsp_ht.c,v 1.19 2014/06/12 15:49:30 deraadt Exp $ */ +/* $OpenBSD: ocsp_ht.c,v 1.20 2014/07/12 14:58:32 miod Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 2006. */ @@ -108,6 +108,9 @@ static int parse_http_line1(char *line); void OCSP_REQ_CTX_free(OCSP_REQ_CTX *rctx) { + if (rctx == NULL) + return; + if (rctx->mem) BIO_free(rctx->mem); free(rctx->iobuf); diff --git a/lib/libssl/src/crypto/x509/x509_vfy.c b/lib/libssl/src/crypto/x509/x509_vfy.c index 9d7a7d12289..d894facd473 100644 --- a/lib/libssl/src/crypto/x509/x509_vfy.c +++ b/lib/libssl/src/crypto/x509/x509_vfy.c @@ -1,4 +1,4 @@ -/* $OpenBSD: x509_vfy.c,v 1.34 2014/07/11 12:52:41 miod Exp $ */ +/* $OpenBSD: x509_vfy.c,v 1.35 2014/07/12 14:58:32 miod Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -1979,6 +1979,9 @@ X509_STORE_CTX_new(void) void X509_STORE_CTX_free(X509_STORE_CTX *ctx) { + if (ctx == NULL) + return; + X509_STORE_CTX_cleanup(ctx); free(ctx); } -- 2.20.1