diff options
author | Derick Rethans <derick@php.net> | 2001-12-15 13:17:55 +0000 |
---|---|---|
committer | Derick Rethans <derick@php.net> | 2001-12-15 13:17:55 +0000 |
commit | 856c9fa57bbd37ad3c69ac01f2e7183e07eff35e (patch) | |
tree | 02b1c49c73ba3fef2350fd1f33d7c7eb7784830d /ext/mcrypt/mcrypt.c | |
parent | c464d42445fbc259ecc1d605fdc6abd1ad2ca32a (diff) | |
download | php-git-856c9fa57bbd37ad3c69ac01f2e7183e07eff35e.tar.gz |
- Fix for bug 14162, invalidate the resource then mcrypt_generic_init fails
Diffstat (limited to 'ext/mcrypt/mcrypt.c')
-rw-r--r-- | ext/mcrypt/mcrypt.c | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/ext/mcrypt/mcrypt.c b/ext/mcrypt/mcrypt.c index b42bad8fec..6f8dbfe420 100644 --- a/ext/mcrypt/mcrypt.c +++ b/ext/mcrypt/mcrypt.c @@ -464,6 +464,7 @@ PHP_FUNCTION(mcrypt_generic_init) int max_key_size, key_size, iv_size; MCRYPT td; int argc; + int result = 0; argc = ZEND_NUM_ARGS(); MCRYPT_CHECK_PARAM_COUNT (3,3) @@ -503,7 +504,27 @@ PHP_FUNCTION(mcrypt_generic_init) } memcpy (iv_s, Z_STRVAL_PP(iv), iv_size); - RETVAL_LONG (mcrypt_generic_init (td, key_s, key_size, iv_s)); + result = mcrypt_generic_init (td, key_s, key_size, iv_s); + + /* If this function fails, close the mcrypt module to prevent crashes + * when further functions want to access this resource */ + if (result < 0) { + zend_list_delete (Z_LVAL_PP(mcryptind)); + switch (result) { + case -3: + php_error (E_WARNING, "mcrypt_generic_init: Key length incorrect"); + break; + case -4: + php_error (E_WARNING, "mcrypt_generic_init: Memory allocation error"); + break; + case -1: + default: + php_error (E_WARNING, "mcrypt_generic_init: Unknown error"); + break; + } + } + RETVAL_LONG (result); + efree (iv_s); efree (key_s); } |