tony2001 Wed Jun 6 22:09:25 2007 UTC Modified files: (Branch: PHP_5_2) /php-src/ext/bcmath bcmath.c Log: MFH: improve the checks for integer overflow http://cvs.php.net/viewvc.cgi/php-src/ext/bcmath/bcmath.c?r1=1.62.2.2.2.6&r2=1.62.2.2.2.7&diff_format=u Index: php-src/ext/bcmath/bcmath.c diff -u php-src/ext/bcmath/bcmath.c:1.62.2.2.2.6 php-src/ext/bcmath/bcmath.c:1.62.2.2.2.7 --- php-src/ext/bcmath/bcmath.c:1.62.2.2.2.6 Thu May 10 09:53:36 2007 +++ php-src/ext/bcmath/bcmath.c Wed Jun 6 22:09:25 2007 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: bcmath.c,v 1.62.2.2.2.6 2007/05/10 09:53:36 tony2001 Exp $ */ +/* $Id: bcmath.c,v 1.62.2.2.2.7 2007/06/06 22:09:25 tony2001 Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -31,7 +31,7 @@ #include "php_bcmath.h" #include "libbcmath/src/bcmath.h" -ZEND_DECLARE_MODULE_GLOBALS(bcmath); +ZEND_DECLARE_MODULE_GLOBALS(bcmath) static PHP_GINIT_FUNCTION(bcmath); static PHP_GSHUTDOWN_FUNCTION(bcmath); @@ -229,7 +229,7 @@ WRONG_PARAM_COUNT; } convert_to_long_ex(scale_param); - scale = (int) (Z_LVAL_PP(scale_param) < 0) ? 0 : Z_LVAL_PP(scale_param); + scale = (int) ((int)Z_LVAL_PP(scale_param) < 0) ? 0 : Z_LVAL_PP(scale_param); break; default: WRONG_PARAM_COUNT; @@ -275,7 +275,7 @@ WRONG_PARAM_COUNT; } convert_to_long_ex(scale_param); - scale = (int) (Z_LVAL_PP(scale_param) < 0) ? 0 : Z_LVAL_PP(scale_param); + scale = (int) ((int)Z_LVAL_PP(scale_param) < 0) ? 0 : Z_LVAL_PP(scale_param); break; default: WRONG_PARAM_COUNT; @@ -321,7 +321,7 @@ WRONG_PARAM_COUNT; } convert_to_long_ex(scale_param); - scale = (int) (Z_LVAL_PP(scale_param) < 0) ? 0 : Z_LVAL_PP(scale_param); + scale = (int) ((int)Z_LVAL_PP(scale_param) < 0) ? 0 : Z_LVAL_PP(scale_param); break; default: WRONG_PARAM_COUNT; @@ -367,7 +367,7 @@ WRONG_PARAM_COUNT; } convert_to_long_ex(scale_param); - scale = (int) (Z_LVAL_PP(scale_param) < 0) ? 0 : Z_LVAL_PP(scale_param); + scale = (int) ((int)Z_LVAL_PP(scale_param) < 0) ? 0 : Z_LVAL_PP(scale_param); break; default: WRONG_PARAM_COUNT; @@ -449,6 +449,7 @@ int left_len, right_len, modulous_len; bc_num first, second, mod, result; long scale = BCG(bc_precision); + int scale_int; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss|l", &left, &left_len, &right, &right_len, &modulous, &modulous_len, &scale) == FAILURE) { return; @@ -461,7 +462,10 @@ php_str2num(&first, left TSRMLS_CC); php_str2num(&second, right TSRMLS_CC); php_str2num(&mod, modulous TSRMLS_CC); - bc_raisemod(first, second, mod, &result, scale TSRMLS_CC); + + scale_int = (int) ((int)scale < 0) ? 0 : scale; + + bc_raisemod(first, second, mod, &result, scale_int TSRMLS_CC); if (result->n_scale > scale) { result->n_scale = scale; } @@ -495,7 +499,7 @@ WRONG_PARAM_COUNT; } convert_to_long_ex(scale_param); - scale = (int) (Z_LVAL_PP(scale_param) < 0) ? 0 : Z_LVAL_PP(scale_param); + scale = (int) ((int)Z_LVAL_PP(scale_param) < 0) ? 0 : Z_LVAL_PP(scale_param); break; default: WRONG_PARAM_COUNT; @@ -541,7 +545,7 @@ WRONG_PARAM_COUNT; } convert_to_long_ex(scale_param); - scale = (int) (Z_LVAL_PP(scale_param) < 0) ? 0 : Z_LVAL_PP(scale_param); + scale = (int) ((int)Z_LVAL_PP(scale_param) < 0) ? 0 : Z_LVAL_PP(scale_param); break; default: WRONG_PARAM_COUNT; @@ -584,7 +588,7 @@ WRONG_PARAM_COUNT; } convert_to_long_ex(scale_param); - scale = (int) (Z_LVAL_PP(scale_param) < 0) ? 0 : Z_LVAL_PP(scale_param); + scale = (int) ((int)Z_LVAL_PP(scale_param) < 0) ? 0 : Z_LVAL_PP(scale_param); break; default: WRONG_PARAM_COUNT;
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php