cvs: php-src /ext/standard array.c string.c /ext/standard/tests/array bug28974.phpt
| From: | Andrey Hristov | Date: | Sun, 11 Jul 2004 21:15:04 +0000 |
| Subject: | cvs: php-src /ext/standard array.c string.c /ext/standard/tests/array bug28974.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-27792@lists.php.net to get a copy of this message | ||
andrey Sun Jul 11 17:15:04 2004 EDT
Added files:
/php-src/ext/standard/tests/array bug28974.phpt
Modified files:
/php-src/ext/standard array.c string.c
Log:
fixing 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.265&r2=1.266&ty=u
Index: php-src/ext/standard/array.c
diff -u php-src/ext/standard/array.c:1.265 php-src/ext/standard/array.c:1.266
--- php-src/ext/standard/array.c:1.265 Sun Jul 11 15:20:05 2004
+++ php-src/ext/standard/array.c Sun Jul 11 17:15:04 2004
@@ -21,7 +21,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: array.c,v 1.265 2004/07/11 19:20:05 andrey Exp $ */
+/* $Id: array.c,v 1.266 2004/07/11 21:15:04 andrey Exp $ */
#include "php.h"
#include "php_ini.h"
@@ -1746,7 +1746,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;
}
@@ -2125,7 +2125,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.419&r2=1.420&ty=u
Index: php-src/ext/standard/string.c
diff -u php-src/ext/standard/string.c:1.419 php-src/ext/standard/string.c:1.420
--- php-src/ext/standard/string.c:1.419 Tue Jul 6 18:16:42 2004
+++ php-src/ext/standard/string.c Sun Jul 11 17:15:04 2004
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: string.c,v 1.419 2004/07/06 22:16:42 iliaa Exp $ */
+/* $Id: string.c,v 1.420 2004/07/11 21:15:04 andrey Exp $ */
/* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */
@@ -237,7 +237,7 @@
}
}
- if ((start + len) > len1) {
+ if (((unsigned) start + (unsigned) len) > len1) {
len = len1 - start;
}
@@ -1901,7 +1901,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;
}
@@ -1998,7 +1998,7 @@
}
}
- if ((f + l) > Z_STRLEN_PP(str)) {
+ if (((unsigned) f + (unsigned) l) > Z_STRLEN_PP(str)) {
l = Z_STRLEN_PP(str) - f;
}
if (Z_TYPE_PP(repl) == IS_ARRAY) {
@@ -2094,7 +2094,7 @@
}
}
- if ((f + l) > Z_STRLEN_PP(tmp_str)) {
+ if (((unsigned) f + (unsigned) l) > Z_STRLEN_PP(tmp_str)) {
l = Z_STRLEN_PP(tmp_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
)