diff --git a/system/core/CodeIgniter.php b/system/core/CodeIgniter.php index e97e9e3aad..e3a6f44b20 100644 --- a/system/core/CodeIgniter.php +++ b/system/core/CodeIgniter.php @@ -56,7 +56,7 @@ * @var string * */ - const CI_VERSION = '3.4.7'; + const CI_VERSION = '3.4.8'; /* * ------------------------------------------------------ diff --git a/system/libraries/Encryption.php b/system/libraries/Encryption.php index b53dac2e83..815464c92f 100644 --- a/system/libraries/Encryption.php +++ b/system/libraries/Encryption.php @@ -371,6 +371,8 @@ public function create_key($length) */ public function encrypt($data, $params = NULL) { + $data === NULL && $data = ''; + if (($params = $this->_get_params($params)) === FALSE) { return FALSE; @@ -470,11 +472,6 @@ protected function _mcrypt_encrypt($data, $params) */ protected function _openssl_encrypt($data, $params) { - if ($data === NULL) - { - return NULL; - } - if (empty($params['handle'])) { return FALSE; @@ -511,6 +508,8 @@ protected function _openssl_encrypt($data, $params) */ public function decrypt($data, $params = NULL) { + $data === NULL && $data = ''; + if (($params = $this->_get_params($params)) === FALSE) { return FALSE; @@ -631,11 +630,6 @@ protected function _mcrypt_decrypt($data, $params) */ protected function _openssl_decrypt($data, $params) { - if ($data === NULL) - { - return NULL; - } - if ($iv_size = openssl_cipher_iv_length($params['handle'])) { $iv = self::substr($data, 0, $iv_size); diff --git a/tests/codeigniter/libraries/Encryption_test.php b/tests/codeigniter/libraries/Encryption_test.php index dca2acad39..5cc9215fb7 100644 --- a/tests/codeigniter/libraries/Encryption_test.php +++ b/tests/codeigniter/libraries/Encryption_test.php @@ -248,6 +248,44 @@ public function test_encrypt_decrypt_custom() // -------------------------------------------------------------------- + /** + * @depends test__get_params + */ + public function test_encrypt_decrypt_null() + { + $this->encryption->initialize(array('key' => str_repeat("\x1", 16))); + + $notices = array(); + set_error_handler(function ($severity, $message) use (&$notices) { + $notices[] = $message; + return TRUE; + }); + + $ciphertext = $this->encryption->encrypt(NULL); + $plaintext = $this->encryption->decrypt($ciphertext); + $null_plaintext = $this->encryption->decrypt(NULL); + + $binary_params = array( + 'cipher' => 'aes-128', + 'mode' => 'cbc', + 'key' => str_repeat("\x1", 16), + 'hmac' => FALSE + ); + $binary_ciphertext = $this->encryption->encrypt(NULL, $binary_params); + $binary_plaintext = $this->encryption->decrypt($binary_ciphertext, $binary_params); + $binary_null_plaintext = $this->encryption->decrypt(NULL, $binary_params); + + restore_error_handler(); + + $this->assertSame(array(), $notices); + $this->assertSame('', $plaintext); + $this->assertFalse($null_plaintext); + $this->assertSame('', $binary_plaintext); + $this->assertFalse($binary_null_plaintext); + } + + // -------------------------------------------------------------------- + /** * _mcrypt_get_handle() test */