diff options
author | Christoph M. Becker <cmbecker69@gmx.de> | 2020-01-21 16:17:25 +0100 |
---|---|---|
committer | Christoph M. Becker <cmbecker69@gmx.de> | 2020-01-21 16:17:25 +0100 |
commit | 9eff906a024578f0ea0bf8b4e318544d70074537 (patch) | |
tree | 1589a88ebd34bae69ab7b2c2f5881edac503e029 | |
parent | 3046e35718e4980a8cf7785fa6ecea51d02ebee8 (diff) | |
download | php-git-9eff906a024578f0ea0bf8b4e318544d70074537.tar.gz |
Fix #79145: openssl memory leak
We must increase the refcount of `return_value` only if `cert` is a
resource; this is already done in `php_openssl_evp_from_zval()`,
though.
-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | ext/openssl/openssl.c | 2 | ||||
-rw-r--r-- | ext/openssl/tests/bug79145.phpt | 26 |
3 files changed, 29 insertions, 2 deletions
@@ -15,6 +15,9 @@ PHP NEWS . Fixed bug #79084 (mysqlnd may fetch wrong column indexes with MYSQLI_BOTH). (cmb) +- OpenSSL: + . Fixed bug #79145 (openssl memory leak). (cmb, Nikita) + - Reflection: . Fixed bug #79115 (ReflectionClass::isCloneable call reflected class __destruct). (Nikita) diff --git a/ext/openssl/openssl.c b/ext/openssl/openssl.c index 4cc3bd5446..7e935ae8ec 100644 --- a/ext/openssl/openssl.c +++ b/ext/openssl/openssl.c @@ -4691,7 +4691,6 @@ PHP_FUNCTION(openssl_pkey_get_public) RETURN_FALSE; } ZVAL_RES(return_value, res); - Z_ADDREF_P(return_value); } /* }}} */ @@ -4733,7 +4732,6 @@ PHP_FUNCTION(openssl_pkey_get_private) RETURN_FALSE; } ZVAL_RES(return_value, res); - Z_ADDREF_P(return_value); } /* }}} */ diff --git a/ext/openssl/tests/bug79145.phpt b/ext/openssl/tests/bug79145.phpt new file mode 100644 index 0000000000..348831189b --- /dev/null +++ b/ext/openssl/tests/bug79145.phpt @@ -0,0 +1,26 @@ +--TEST-- +Bug #79145 (openssl memory leak) +--SKIPIF-- +<?php +if (!extension_loaded('openssl')) die('skip openssl extension not available'); +if (getenv('SKIP_SLOW_TESTS')) die('skip slow test'); +?> +--FILE-- +<?php +$b = '-----BEGIN PUBLIC KEY----- +MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDaFhc31WeskqxwI+Si5R/fZrLK +pJOlABiI3RZfKCHJVrXl3IvcHDFM/BHKUJoSi/ee8GS9iw0G4Z1eCzJdthXxHARh +j85Q5OliVxOdB1LoTOsOmfFf/fdvpU3DsOWsDKlVrL41MHxXorwrwOiys/r/gv2d +C9C4JmhTOjBVAK8SewIDAQAC +-----END PUBLIC KEY-----'; + +$start = memory_get_usage(true); +for ($i = 0; $i < 100000; $i++) { + $a = openssl_get_publickey($b); + openssl_free_key($a); +} +$end = memory_get_usage(true); +var_dump($end <= 1.1 * $start); +?> +--EXPECT-- +bool(true) |