Bug #74099 [NEW]: Memory leak with openssl_encrypt()

From: Date: Wed, 15 Feb 2017 09:30:18 +0000
Subject: Bug #74099 [NEW]: Memory leak with openssl_encrypt()
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-207385@lists.php.net to get a copy of this message
From:             marcel at webdisplay dot nl
Operating system: macOS Sierra
PHP version:      7.1.1
Package:          OpenSSL related
Bug Type:         Bug
Bug description:Memory leak with openssl_encrypt()

Description:
------------
Encrypting an empty string in AES-256-GCM should return an empty string
and valid tag but instead it returns 32 bytes of data from memory which
could leak information.

Test script:
---------------
$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);

// $ciphertext should be an empty string but it is not in PHP 7.1.*
// Instead it returns random data from memory!
printf("ciphertext=%s, tag=%s", bin2hex($ciphertext), bin2hex($tag));


Expected result:
----------------
An empty string must be returned

Actual result:
--------------
A 32-byte string from memory is returned

-- 
Edit bug report at https://bugs.php.net/bug.php?id=74099&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=74099&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=74099&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=74099&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=74099&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=74099&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=74099&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=74099&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=74099&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=74099&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=74099&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=74099&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=74099&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=74099&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=74099&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=74099&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=74099&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=74099&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=74099&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=74099&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=74099&r=mysqlcfg



Thread (3 messages)

« previous php.bugs (#207385) next »