Skip to content

Commit

Permalink
eliminate dynamic property
Browse files Browse the repository at this point in the history
  • Loading branch information
terrafrost committed Dec 18, 2022
1 parent e38b76f commit 077eccc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/mcrypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@ function phpseclib_mcrypt_module_open($algorithm, $algorithm_directory, $mode, $

$cipher->disablePadding();

$cipher->key = null;

return $cipher;
}

Expand Down Expand Up @@ -688,7 +690,6 @@ function phpseclib_mcrypt_generic_init(Base $td, $key, $iv)
phpseclib_set_iv($td, $iv);

$td->enableContinuousBuffer();
$td->mcrypt_polyfill_init = true;

return 0;
}
Expand All @@ -710,7 +711,7 @@ function phpseclib_mcrypt_generic_helper(Base $td, &$data, $op)
// Warning: mcrypt_generic(): supplied resource is not a valid MCrypt resource
// that error doesn't really make a lot of sense in this context since $td is not a resource nor should it be one.
// in light of that we'll just display the same error that you get when you don't call mcrypt_generic_init() at all
if (!isset($td->mcrypt_polyfill_init)) {
if (!isset($td->key)) {
trigger_error('m' . $op . '_generic(): Operation disallowed prior to mcrypt_generic_init().', E_USER_WARNING);
return false;
}
Expand Down Expand Up @@ -786,13 +787,13 @@ function phpseclib_mdecrypt_generic(Base $td, $data)
*/
function phpseclib_mcrypt_generic_deinit(Base $td)
{
if (!isset($td->mcrypt_polyfill_init)) {
if (!isset($td->key)) {
trigger_error('mcrypt_generic_deinit(): Could not terminate encryption specifier', E_USER_WARNING);
return false;
}

$td->disableContinuousBuffer();
unset($td->mcrypt_polyfill_init);
$td->key = null;
return true;
}

Expand All @@ -807,7 +808,7 @@ function phpseclib_mcrypt_generic_deinit(Base $td)
*/
function phpseclib_mcrypt_module_close(Base $td)
{
//unset($td->mcrypt_polyfill_init);
$td->key = null;
return true;
}

Expand Down
8 changes: 8 additions & 0 deletions tests/MCryptCompatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,14 @@ public function testOFB()
}
}

public function testModuleOpenWithoutInit()
{
$this->setExpectedException('PHPUnit_Framework_Error_Warning');

$td = phpseclib_mcrypt_module_open('rijndael-128', '', 'cbc', '');
$result = phpseclib_mcrypt_generic($td, 'zzz');
}

public function mcryptModuleNameProvider()
{
return array(
Expand Down

0 comments on commit 077eccc

Please sign in to comment.