summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStanislav Malyshev <stas@php.net>2008-08-05 20:11:17 +0000
committerStanislav Malyshev <stas@php.net>2008-08-05 20:11:17 +0000
commitadf6be4bfbd6f7c7b3fee16c54dbff50a8db59c3 (patch)
tree4650af3221bc2c836bd0e1ee308b8a5495832fef
parentddcb5042f5993fa5a0a72060d36cd5ae8c31d4af (diff)
downloadphp-git-adf6be4bfbd6f7c7b3fee16c54dbff50a8db59c3.tar.gz
fix memnstr bug, by Laurent Gaffie
-rw-r--r--Zend/zend_operators.h3
-rw-r--r--ext/standard/tests/strings/explode_bug.phpt15
2 files changed, 18 insertions, 0 deletions
diff --git a/Zend/zend_operators.h b/Zend/zend_operators.h
index 2fa4097ec2..03a4ed35d4 100644
--- a/Zend/zend_operators.h
+++ b/Zend/zend_operators.h
@@ -220,6 +220,9 @@ zend_memnstr(char *haystack, char *needle, int needle_len, char *end)
char *p = haystack;
char ne = needle[needle_len-1];
+ if(needle_len > end-haystack) {
+ return NULL;
+ }
end -= needle_len;
while (p <= end) {
diff --git a/ext/standard/tests/strings/explode_bug.phpt b/ext/standard/tests/strings/explode_bug.phpt
new file mode 100644
index 0000000000..9766f0b8f4
--- /dev/null
+++ b/ext/standard/tests/strings/explode_bug.phpt
@@ -0,0 +1,15 @@
+--TEST--
+Explode/memnstr bug
+--INI--
+error_reporting=2047
+memory_limit=256M
+--FILE--
+<?php
+$res = explode(str_repeat("A",145999999),1);
+var_dump($res);
+?>
+--EXPECTF--
+array(1) {
+ [0]=>
+ string(1) "1"
+}