summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJelle van der Waa <jelle@vdwaa.nl>2017-06-06 16:45:39 +0200
committerJakub Zelenka <bukka@php.net>2017-06-16 16:51:50 +0100
commitf19dfac830a728f4d77e7e4d1aae3eb05c9496ac (patch)
tree8157953c1d770ebf5d0244d773b306ff856906dc
parent648be8600ff89e1b0e4a4ad25cebad42b53bed6d (diff)
downloadphp-git-f19dfac830a728f4d77e7e4d1aae3eb05c9496ac.tar.gz
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.
-rw-r--r--ext/openssl/openssl.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/ext/openssl/openssl.c b/ext/openssl/openssl.c
index 6b382ba6bd..6203267a05 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;