Browse Source

fix #33605 (substr_compare() crashes with negative offset & length)

PHP-5.1
Antony Dovgal 21 years ago
parent
commit
3baf1f7632
  1. 2
      NEWS
  2. 8
      ext/standard/string.c

2
NEWS

@ -10,6 +10,8 @@ PHP NEWS
- Fixed memory corruption in pg_copy_from() in case the as_null parameter was - Fixed memory corruption in pg_copy_from() in case the as_null parameter was
passed. (Derick) passed. (Derick)
- Fixed crash inside stream_get_line() when length parameter equals 0. (Ilia) - Fixed crash inside stream_get_line() when length parameter equals 0. (Ilia)
- Fixed bug #33605 (substr_compare() crashes with negative offset and length).
(Tony)
- Fixed bug #33578 (strtotime() doesn't understand "11 Oct" format). (Derick) - Fixed bug #33578 (strtotime() doesn't understand "11 Oct" format). (Derick)
- Fixed bug #33562 (date("") crashes). (Derick) - Fixed bug #33562 (date("") crashes). (Derick)
- Fixed bug #33536 (strtotime() defaults to now even on non time string). - Fixed bug #33536 (strtotime() defaults to now even on non time string).

8
ext/standard/string.c

@ -4446,6 +4446,10 @@ PHP_FUNCTION(substr_count)
if (ac > 2) { if (ac > 2) {
convert_to_long_ex(offset); convert_to_long_ex(offset);
if (Z_LVAL_PP(offset) < 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Offset should be greater then or equal to 0.");
RETURN_FALSE;
}
p += Z_LVAL_PP(offset); p += Z_LVAL_PP(offset);
if (p > endp) { if (p > endp) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Offset value %ld exceeds string length.", Z_LVAL_PP(offset)); php_error_docref(NULL TSRMLS_CC, E_WARNING, "Offset value %ld exceeds string length.", Z_LVAL_PP(offset));
@ -4453,6 +4457,10 @@ PHP_FUNCTION(substr_count)
} }
if (ac == 4) { if (ac == 4) {
convert_to_long_ex(length); convert_to_long_ex(length);
if (Z_LVAL_PP(length) <= 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length should be greater than 0.");
RETURN_FALSE;
}
if ((p + Z_LVAL_PP(length)) > endp) { if ((p + Z_LVAL_PP(length)) > endp) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length value %ld exceeds string length.", Z_LVAL_PP(length)); php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length value %ld exceeds string length.", Z_LVAL_PP(length));
RETURN_FALSE; RETURN_FALSE;

Loading…
Cancel
Save