cvs: php-src(PHP_4_3) /ext/standard array.c string.c /ext/standard/tests/array bug28974.phpt

From: Date: Sun, 11 Jul 2004 21:24:48 +0000
Subject: cvs: php-src(PHP_4_3) /ext/standard array.c string.c /ext/standard/tests/array bug28974.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-27793@lists.php.net to get a copy of this message
andrey Sun Jul 11 17:24:48 2004 EDT Added files: (Branch: PHP_4_3) /php-src/ext/standard/tests/array bug28974.phpt Modified files: /php-src/ext/standard array.c string.c Log: MFH: fixed bug #28974 : overflow in array_slice() The same kind of overflow appeared in array_splice(), substr() and substr_replace() http://cvs.php.net/diff.php/php-src/ext/standard/array.c?r1=1.199.2.33&r2=1.199.2.34&ty=u Index: php-src/ext/standard/array.c diff -u php-src/ext/standard/array.c:1.199.2.33 php-src/ext/standard/array.c:1.199.2.34 --- php-src/ext/standard/array.c:1.199.2.33 Thu Jul 8 13:07:25 2004 +++ php-src/ext/standard/array.c Sun Jul 11 17:24:47 2004 @@ -22,7 +22,7 @@ */ -/* $Id: array.c,v 1.199.2.33 2004/07/08 17:07:25 iliaa Exp $ */ +/* $Id: array.c,v 1.199.2.34 2004/07/11 21:24:47 andrey Exp $ */ #include "php.h" #include "php_ini.h" @@ -1583,7 +1583,7 @@ /* ..and the length */ if (length < 0) { length = num_in-offset+length; - } else if (offset+length > num_in) { + } else if (((unsigned) offset + (unsigned) length) > num_in) { length = num_in-offset; } @@ -1960,7 +1960,7 @@ /* ..and the length */ if (length_val < 0) { length_val = num_in-offset_val+length_val; - } else if (offset_val+length_val > num_in) { + } else if (((unsigned) offset_val + (unsigned)length_val) > num_in) { length_val = num_in-offset_val; } http://cvs.php.net/diff.php/php-src/ext/standard/string.c?r1=1.333.2.43&r2=1.333.2.44&ty=u Index: php-src/ext/standard/string.c diff -u php-src/ext/standard/string.c:1.333.2.43 php-src/ext/standard/string.c:1.333.2.44 --- php-src/ext/standard/string.c:1.333.2.43 Tue Jul 6 18:16:47 2004 +++ php-src/ext/standard/string.c Sun Jul 11 17:24:47 2004 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: string.c,v 1.333.2.43 2004/07/06 22:16:47 iliaa Exp $ */ +/* $Id: string.c,v 1.333.2.44 2004/07/11 21:24:47 andrey Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ @@ -234,7 +234,7 @@ } } - if ((start + len) > len1) { + if (((unsigned) start + (unsigned) len) > len1) { len = len1 - start; } @@ -1636,7 +1636,7 @@ RETURN_FALSE; } - if ((f + l) > Z_STRLEN_PP(str)) { + if (((unsigned) f + (unsigned) l) > Z_STRLEN_PP(str)) { l = Z_STRLEN_PP(str) - f; } @@ -1698,7 +1698,7 @@ } } - if ((f + l) > Z_STRLEN_PP(str)) { + if (((unsigned) f + (unsigned) l) > Z_STRLEN_PP(str)) { l = Z_STRLEN_PP(str) - f; } http://cvs.php.net/co.php/php-src/ext/standard/tests/array/bug28974.phpt?r=1.1&p=1 Index: php-src/ext/standard/tests/array/bug28974.phpt +++ php-src/ext/standard/tests/array/bug28974.phpt --TEST-- Bug #28974 array_(p)slice() treats large lengths incorrectly - overflow --FILE-- <?php $a = $b = $c = array(0,1,2,3,4,5); print_r($a); // this is ok: print_r(array_slice($a,2,2147483645)); // this is wrong: print_r(array_slice($a,2,2147483646)); echo 'print_r(array_splice($a,2,1));'."\n"; print_r(array_splice($a,2,1)); echo "\$a is :"; print_r($a); echo 'print_r(array_splice($b,2,2147483645));'."\n"; print_r(array_splice($b,2,2147483645)); echo "\$b is :"; print_r($b); // this is wrong: echo 'print_r(array_splice($c,2,2147483646));'."\n"; print_r(array_splice($c,2,2147483646)); echo "\$c is :"; print_r($c); ?> --EXPECT-- Array ( [0] => 0 [1] => 1 [2] => 2 [3] => 3 [4] => 4 [5] => 5 ) Array ( [0] => 2 [1] => 3 [2] => 4 [3] => 5 ) Array ( [0] => 2 [1] => 3 [2] => 4 [3] => 5 ) print_r(array_splice($a,2,1)); Array ( [0] => 2 ) $a is :Array ( [0] => 0 [1] => 1 [2] => 3 [3] => 4 [4] => 5 ) print_r(array_splice($b,2,2147483645)); Array ( [0] => 2 [1] => 3 [2] => 4 [3] => 5 ) $b is :Array ( [0] => 0 [1] => 1 ) print_r(array_splice($c,2,2147483646)); Array ( [0] => 2 [1] => 3 [2] => 4 [3] => 5 ) $c is :Array ( [0] => 0 [1] => 1 )

« previous php.cvs (#27793) next »