com php-src: openssl: Fix spkstr and spki leak in openssl_spk i_new: ext/openssl/openssl.c
| From: | Jakub Zelenka | Date: | Fri, 16 Jun 2017 15:51:50 +0000 |
| Subject: | com php-src: openssl: Fix spkstr and spki leak in openssl_spk i_new: ext/openssl/openssl.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-98084@lists.php.net to get a copy of this message | ||
Commit: f19dfac830a728f4d77e7e4d1aae3eb05c9496ac
Author: Jelle van der Waa <jelle@vdwaa.nl> Tue, 6 Jun 2017 16:45:39 +0200
Committer: Jakub Zelenka <bukka@php.net> Fri, 16 Jun 2017 16:51:50 +0100
Parents: 648be8600ff89e1b0e4a4ad25cebad42b53bed6d
Branches: PHP-7.0
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=f19dfac830a728f4d77e7e4d1aae3eb05c9496ac
Log:
openssl: Fix spkstr and spki leak in openssl_spki_new
spkstr is not free'd when running the test and valgrind reports a leak
of 32,318 bytes. The free condition is not met since keyresource is not
NULL, apart from that OPENSSL_free actually free's the allocated memory
by OPENSSL_malloc inside OpenSSL.
Valgrind reports 768 bytes leaked in openssl_spki_new when running the
testsuite. Remove the keyresource check to always free spki.
Changed paths:
M ext/openssl/openssl.c
Diff:
diff --git a/ext/openssl/openssl.c b/ext/openssl/openssl.c
index 6b382ba..6203267 100644
--- a/ext/openssl/openssl.c
+++ b/ext/openssl/openssl.c
@@ -1760,21 +1760,19 @@ PHP_FUNCTION(openssl_spki_new)
s = zend_string_alloc(strlen(spkac) + strlen(spkstr), 0);
sprintf(ZSTR_VAL(s), "%s%s", spkac, spkstr);
ZSTR_LEN(s) = strlen(ZSTR_VAL(s));
+ OPENSSL_free(spkstr);
RETVAL_STR(s);
goto cleanup;
cleanup:
- if (keyresource == NULL && spki != NULL) {
+ if (spki != NULL) {
NETSCAPE_SPKI_free(spki);
}
if (keyresource == NULL && pkey != NULL) {
EVP_PKEY_free(pkey);
}
- if (keyresource == NULL && spkstr != NULL) {
- efree(spkstr);
- }
if (s && ZSTR_LEN(s) <= 0) {
RETVAL_FALSE;