cvs: php4(PHP_4_0_7) /ext/mcrypt mcrypt.c

From: Date: Sat, 15 Dec 2001 13:19:38 +0000
Subject: cvs: php4(PHP_4_0_7) /ext/mcrypt mcrypt.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-8648@lists.php.net to get a copy of this message
derick Sat Dec 15 08:19:38 2001 EDT Modified files: (Branch: PHP_4_0_7) /php4/ext/mcrypt mcrypt.c Log: - MFH for bug 14162 Index: php4/ext/mcrypt/mcrypt.c diff -u php4/ext/mcrypt/mcrypt.c:1.57.2.7 php4/ext/mcrypt/mcrypt.c:1.57.2.8 --- php4/ext/mcrypt/mcrypt.c:1.57.2.7 Thu Dec 13 16:11:32 2001 +++ php4/ext/mcrypt/mcrypt.c Sat Dec 15 08:19:37 2001 @@ -464,6 +464,7 @@ argc = ZEND_NUM_ARGS(); MCRYPT_CHECK_PARAM_COUNT (3,3) + int result = 0; zend_get_parameters_ex(3, &mcryptind, &key, &iv); ZEND_FETCH_RESOURCE (td, MCRYPT, mcryptind, -1, "MCrypt", le_mcrypt); convert_to_string_ex (key); @@ -500,7 +501,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 (#8648) next »