From a186312832207437e4783024dcdece5232ac6c39 Mon Sep 17 00:00:00 2001 From: Chuan Ma Date: Mon, 24 Mar 2014 23:24:41 -0400 Subject: [PATCH] Fix #66942: openssl_seal() memory leak Fix #66952: memory leak in openssl_open() --- NEWS | 4 ++++ ext/openssl/openssl.c | 24 ++++++++++++------------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/NEWS b/NEWS index 2d98de7fa0c..6caf4c41d77 100644 --- a/NEWS +++ b/NEWS @@ -40,6 +40,10 @@ PHP NEWS - LDAP: . Fixed issue with null bytes in LDAP bindings. (Matthew Daley) +- OpenSSL: + . Fix bug #66942 (memory leak in openssl_seal()). (Chuan Ma) + . Fix bug #66952 (memory leak in openssl_open()). (Chuan Ma) + - SimpleXML: . Fixed bug #66084 (simplexml_load_string() mangles empty node name) (Anatol) diff --git a/ext/openssl/openssl.c b/ext/openssl/openssl.c index 88ad2ef1293..257681f045f 100755 --- a/ext/openssl/openssl.c +++ b/ext/openssl/openssl.c @@ -4321,6 +4321,7 @@ PHP_FUNCTION(openssl_seal) if (!EVP_EncryptInit(&ctx,cipher,NULL,NULL)) { RETVAL_FALSE; + EVP_CIPHER_CTX_cleanup(&ctx); goto clean_exit; } @@ -4331,10 +4332,12 @@ PHP_FUNCTION(openssl_seal) #endif /* allocate one byte extra to make room for \0 */ buf = emalloc(data_len + EVP_CIPHER_CTX_block_size(&ctx)); + EVP_CIPHER_CTX_cleanup(&ctx); if (!EVP_SealInit(&ctx, cipher, eks, eksl, NULL, pkeys, nkeys) || !EVP_SealUpdate(&ctx, buf, &len1, (unsigned char *)data, data_len)) { RETVAL_FALSE; efree(buf); + EVP_CIPHER_CTX_cleanup(&ctx); goto clean_exit; } @@ -4367,6 +4370,7 @@ PHP_FUNCTION(openssl_seal) efree(buf); } RETVAL_LONG(len1 + len2); + EVP_CIPHER_CTX_cleanup(&ctx); clean_exit: for (i=0; i