mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-21 01:28:47 +02:00
Prevent a server crash when using together APC cache and Mcrypt
SVN:trunk[2498]
This commit is contained in:
@@ -1609,6 +1609,22 @@ class AttributeEncryptedString extends AttributeString
|
||||
self::$sKey = MetaModel::GetConfig()->GetEncryptionKey();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* When the attribute definitions are stored in APC cache:
|
||||
* 1) The static class variable $sKey is NOT serialized
|
||||
* 2) The object's constructor is NOT called upon wakeup
|
||||
* 3) mcrypt may crash the server if passed an empty key !!
|
||||
*
|
||||
* So let's restore the key (if needed) when waking up
|
||||
**/
|
||||
public function __wakeup()
|
||||
{
|
||||
if (self::$sKey == null)
|
||||
{
|
||||
self::$sKey = MetaModel::GetConfig()->GetEncryptionKey();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected function GetSQLCol() {return "TINYBLOB";}
|
||||
|
||||
|
||||
@@ -220,9 +220,16 @@ class SimpleCryptMcryptEngine implements CryptEngine
|
||||
{
|
||||
$iv = substr($encrypted_data, 0, mcrypt_enc_get_iv_size($this->td));
|
||||
$string = substr($encrypted_data, mcrypt_enc_get_iv_size($this->td));
|
||||
mcrypt_generic_init($this->td, $key, $iv);
|
||||
$decrypted_data = rtrim(mdecrypt_generic($this->td, $string), "\0");
|
||||
mcrypt_generic_deinit($this->td);
|
||||
$r = mcrypt_generic_init($this->td, $key, $iv);
|
||||
if (($r < 0) || ($r === false))
|
||||
{
|
||||
$decrypted_data = '** decryption error **';
|
||||
}
|
||||
else
|
||||
{
|
||||
$decrypted_data = rtrim(mdecrypt_generic($this->td, $string), "\0");
|
||||
mcrypt_generic_deinit($this->td);
|
||||
}
|
||||
return $decrypted_data;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user