cvs: php4 /ext/mcrypt mcrypt.c

From: Date: Sat, 15 Dec 2001 13:17:56 +0000
Subject: cvs: php4 /ext/mcrypt mcrypt.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-8646@lists.php.net to get a copy of this message
derick Sat Dec 15 08:17:56 2001 EDT Modified files: /php4/ext/mcrypt mcrypt.c Log: - Fix for bug 14162, invalidate the resource then mcrypt_generic_init fails Index: php4/ext/mcrypt/mcrypt.c diff -u php4/ext/mcrypt/mcrypt.c:1.70 php4/ext/mcrypt/mcrypt.c:1.71 --- php4/ext/mcrypt/mcrypt.c:1.70 Thu Dec 13 16:12:53 2001 +++ php4/ext/mcrypt/mcrypt.c Sat Dec 15 08:17:55 2001 @@ -464,6 +464,7 @@ 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 @@ } 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); }

« previous php.cvs (#8646) next »