]> granicus.if.org Git - php/commitdiff
fix memnstr bug by Laurent Gaffie
authorStanislav Malyshev <stas@php.net>
Tue, 5 Aug 2008 21:23:20 +0000 (21:23 +0000)
committerStanislav Malyshev <stas@php.net>
Tue, 5 Aug 2008 21:23:20 +0000 (21:23 +0000)
Zend/zend_operators.h
ext/standard/tests/strings/explode_bug.phpt [new file with mode: 0644]

index d23e0f342cdd89bc828ac392d10fe328c91be2c2..2d1614b14f7c71fbde79136230da442982b402da 100644 (file)
@@ -234,6 +234,9 @@ zend_memnstr(char *haystack, char *needle, int needle_len, char *end)
        if (needle_len == 1) {
                return (char *)memchr(p, *needle, (end-p));
        }
+       if(needle_len > end-haystack) {
+               return NULL;
+       }
 
        end -= needle_len;
 
diff --git a/ext/standard/tests/strings/explode_bug.phpt b/ext/standard/tests/strings/explode_bug.phpt
new file mode 100644 (file)
index 0000000..9766f0b
--- /dev/null
@@ -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"
+}