mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
Fixed #74099 - Memory leak with openssl_encrypt()
This commit is contained in:
parent
c240feb7f4
commit
15b8b124ae
3 changed files with 22 additions and 3 deletions
1
NEWS
1
NEWS
|
@ -42,6 +42,7 @@ PHP NEWS
|
||||||
- OpenSSL:
|
- OpenSSL:
|
||||||
. Fixed bug #74022 (PHP Fast CGI crashes when reading from a pfx file).
|
. Fixed bug #74022 (PHP Fast CGI crashes when reading from a pfx file).
|
||||||
(Anatol)
|
(Anatol)
|
||||||
|
. Fixed bug #74099 (Memory leak with openssl_encrypt()). (Andrew Nester)
|
||||||
|
|
||||||
- Standard:
|
- Standard:
|
||||||
. Fixed bug #74005 (mail.add_x_header causes RFC-breaking lone line feed).
|
. Fixed bug #74005 (mail.add_x_header causes RFC-breaking lone line feed).
|
||||||
|
|
|
@ -6309,8 +6309,7 @@ static int php_openssl_cipher_update(const EVP_CIPHER *cipher_type,
|
||||||
|
|
||||||
*poutbuf = zend_string_alloc((int)data_len + EVP_CIPHER_block_size(cipher_type), 0);
|
*poutbuf = zend_string_alloc((int)data_len + EVP_CIPHER_block_size(cipher_type), 0);
|
||||||
|
|
||||||
if ((!enc || data_len > 0) &&
|
if (!EVP_CipherUpdate(cipher_ctx, (unsigned char*)ZSTR_VAL(*poutbuf),
|
||||||
!EVP_CipherUpdate(cipher_ctx, (unsigned char*)ZSTR_VAL(*poutbuf),
|
|
||||||
&i, (unsigned char *)data, (int)data_len)) {
|
&i, (unsigned char *)data, (int)data_len)) {
|
||||||
/* we don't show warning when we fail but if we ever do, then it should look like this:
|
/* we don't show warning when we fail but if we ever do, then it should look like this:
|
||||||
if (mode->is_single_run_aead && !enc) {
|
if (mode->is_single_run_aead && !enc) {
|
||||||
|
@ -6366,7 +6365,6 @@ PHP_FUNCTION(openssl_encrypt)
|
||||||
php_error_docref(NULL, E_WARNING, "Failed to create cipher context");
|
php_error_docref(NULL, E_WARNING, "Failed to create cipher context");
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
php_openssl_load_cipher_mode(&mode, cipher_type);
|
php_openssl_load_cipher_mode(&mode, cipher_type);
|
||||||
|
|
||||||
if (php_openssl_cipher_init(cipher_type, cipher_ctx, &mode,
|
if (php_openssl_cipher_init(cipher_type, cipher_ctx, &mode,
|
||||||
|
|
20
ext/openssl/tests/bug74099.phpt
Normal file
20
ext/openssl/tests/bug74099.phpt
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
--TEST--
|
||||||
|
Bug #74099 Memory leak with openssl_encrypt()
|
||||||
|
--SKIPIF--
|
||||||
|
<?php
|
||||||
|
if (!extension_loaded("openssl")) die("skip");
|
||||||
|
?>
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
$aad = random_bytes(32);
|
||||||
|
$iv = random_bytes(16);
|
||||||
|
$key = random_bytes(32);
|
||||||
|
|
||||||
|
$plaintext = '';
|
||||||
|
$tag = null;
|
||||||
|
|
||||||
|
$ciphertext = openssl_encrypt($plaintext, 'aes-256-gcm', $key, \OPENSSL_RAW_DATA, $iv, $tag, $aad);
|
||||||
|
var_dump($ciphertext);
|
||||||
|
?>
|
||||||
|
--EXPECTF--
|
||||||
|
string(0) ""
|
Loading…
Add table
Add a link
Reference in a new issue