From e9c572c56a6b9de69b6b334e56df19d11d0304ef Mon Sep 17 00:00:00 2001 From: miod <> Date: Mon, 20 Jul 2015 15:45:29 +0000 Subject: Various memory leaks upon error or unchecked allocations. ok doug@ --- src/lib/libcrypto/hmac/hm_ameth.c | 17 +++++++++++++---- src/lib/libssl/src/crypto/hmac/hm_ameth.c | 17 +++++++++++++---- 2 files changed, 26 insertions(+), 8 deletions(-) (limited to 'src/lib') diff --git a/src/lib/libcrypto/hmac/hm_ameth.c b/src/lib/libcrypto/hmac/hm_ameth.c index f4fa6f4bc3..da3471c4fd 100644 --- a/src/lib/libcrypto/hmac/hm_ameth.c +++ b/src/lib/libcrypto/hmac/hm_ameth.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hm_ameth.c,v 1.8 2014/07/11 08:44:48 jsing Exp $ */ +/* $OpenBSD: hm_ameth.c,v 1.9 2015/07/20 15:45:29 miod Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 2007. */ @@ -112,10 +112,17 @@ old_hmac_decode(EVP_PKEY *pkey, const unsigned char **pder, int derlen) ASN1_OCTET_STRING *os; os = ASN1_OCTET_STRING_new(); - if (!os || !ASN1_OCTET_STRING_set(os, *pder, derlen)) - return 0; - EVP_PKEY_assign(pkey, EVP_PKEY_HMAC, os); + if (os == NULL) + goto err; + if (ASN1_OCTET_STRING_set(os, *pder, derlen) == 0) + goto err; + if (EVP_PKEY_assign(pkey, EVP_PKEY_HMAC, os) == 0) + goto err; return 1; + +err: + ASN1_OCTET_STRING_free(os); + return 0; } static int @@ -127,6 +134,8 @@ old_hmac_encode(const EVP_PKEY *pkey, unsigned char **pder) if (pder) { if (!*pder) { *pder = malloc(os->length); + if (*pder == NULL) + return -1; inc = 0; } else inc = 1; diff --git a/src/lib/libssl/src/crypto/hmac/hm_ameth.c b/src/lib/libssl/src/crypto/hmac/hm_ameth.c index f4fa6f4bc3..da3471c4fd 100644 --- a/src/lib/libssl/src/crypto/hmac/hm_ameth.c +++ b/src/lib/libssl/src/crypto/hmac/hm_ameth.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hm_ameth.c,v 1.8 2014/07/11 08:44:48 jsing Exp $ */ +/* $OpenBSD: hm_ameth.c,v 1.9 2015/07/20 15:45:29 miod Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 2007. */ @@ -112,10 +112,17 @@ old_hmac_decode(EVP_PKEY *pkey, const unsigned char **pder, int derlen) ASN1_OCTET_STRING *os; os = ASN1_OCTET_STRING_new(); - if (!os || !ASN1_OCTET_STRING_set(os, *pder, derlen)) - return 0; - EVP_PKEY_assign(pkey, EVP_PKEY_HMAC, os); + if (os == NULL) + goto err; + if (ASN1_OCTET_STRING_set(os, *pder, derlen) == 0) + goto err; + if (EVP_PKEY_assign(pkey, EVP_PKEY_HMAC, os) == 0) + goto err; return 1; + +err: + ASN1_OCTET_STRING_free(os); + return 0; } static int @@ -127,6 +134,8 @@ old_hmac_encode(const EVP_PKEY *pkey, unsigned char **pder) if (pder) { if (!*pder) { *pder = malloc(os->length); + if (*pder == NULL) + return -1; inc = 0; } else inc = 1; -- cgit v1.2.3-55-g6feb