]> granicus.if.org Git - php/commitdiff
openssl: Fix spkstr and spki leak in openssl_spki_new
authorJelle van der Waa <jelle@vdwaa.nl>
Tue, 6 Jun 2017 14:45:39 +0000 (16:45 +0200)
committerJakub Zelenka <bukka@php.net>
Fri, 16 Jun 2017 15:51:50 +0000 (16:51 +0100)
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.

ext/openssl/openssl.c

index 6b382ba6bd72afac090d7a056feb47affa902cd1..6203267a0579350372304f69f601c6022c251bc1 100644 (file)
@@ -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;