From: Moriyoshi Koizumi Date: Fri, 25 Jul 2008 12:50:14 +0000 (+0000) Subject: - fix a typo in mb_stripos() that caused segfault. X-Git-Tag: BEFORE_HEAD_NS_CHANGE~1046 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e8741cc4fc31e09a6474ea9e0da70a2592d2e2f9;p=php - fix a typo in mb_stripos() that caused segfault. (noticed by bs@php.net, thanks). --- diff --git a/ext/mbstring/mbstring.c b/ext/mbstring/mbstring.c index 10a0648cc8..5ee8762ba9 100644 --- a/ext/mbstring/mbstring.c +++ b/ext/mbstring/mbstring.c @@ -2236,10 +2236,13 @@ PHP_FUNCTION(mb_stripos) n = -1; offset = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|ls", (char **)&haystack.val, (int *)&haystack.len, (char **)needle.val, (int *)&needle.len, &offset, &from_encoding, &from_encoding_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|ls", (char **)&haystack.val, (int *)&haystack.len, (char **)&needle.val, (int *)&needle.len, &offset, &from_encoding, &from_encoding_len) == FAILURE) { + RETURN_FALSE; + } + if (needle.len == 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty delimiter."); RETURN_FALSE; } - n = php_mb_stripos(0, (char *)haystack.val, haystack.len, (char *)needle.val, needle.len, offset, from_encoding TSRMLS_CC); if (n >= 0) { diff --git a/ext/mbstring/tests/mb_stripos.phpt b/ext/mbstring/tests/mb_stripos.phpt new file mode 100644 index 0000000000..330ad409b4 --- /dev/null +++ b/ext/mbstring/tests/mb_stripos.phpt @@ -0,0 +1,175 @@ +--TEST-- +mb_stripos() +--SKIPIF-- + +--FILE-- + + +--EXPECT-- +== POSITIVE OFFSET == +10 +0 +3 +0 +34 +30 +33 +30 +== NEGATIVE OFFSET == +ERR: Warning +OK_NEGATIVE_OFFSET +ERR: Warning +OK_NEGATIVE_OFFSET +ERR: Warning +OK_NEGATIVE_OFFSET +ERR: Warning +OK_NEGATIVE_OFFSET +ERR: Warning +OK_NEGATIVE_OFFSET +ERR: Warning +OK_NEGATIVE_OFFSET +ERR: Warning +OK_NEGATIVE_OFFSET +ERR: Warning +OK_NEGATIVE_OFFSET +== OUT OF RANGE == +OK_OUT_RANGE +OK_OUT_RANGE +OK_OUT_RANGE +OK_OUT_RANGE +== NON-EXISTENT == +OK_STR +OK_NEWLINE +== NO ENCODING PARAMETER == +10 +0 +3 +0 +OK_STR +OK_NEWLINE +== NO OFFSET AND ENCODING PARAMETER == +10 +0 +3 +0 +OK_STR +OK_NEWLINE +== INVALID PARAMETER TEST == +ERR: Warning +OK_NULL +ERR: Warning +OK_ARRAY +ERR: Warning +OK_OBJECT +ERR: Warning +OK_BAD_ENCODING + diff --git a/ext/mbstring/tests/mb_stripos_basic.phpt b/ext/mbstring/tests/mb_stripos_basic.phpt new file mode 100644 index 0000000000..ee62df7dcc --- /dev/null +++ b/ext/mbstring/tests/mb_stripos_basic.phpt @@ -0,0 +1,153 @@ +--TEST-- +Test mb_stripos() function : basic functionality +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +*** Testing mb_stripos() : basic functionality*** + +-- ISO-8859-1 string 1 -- +int(4) + +-- ISO-8859-1 string 2 -- +int(4) + +-- ISO-8859-1 string 3 -- +int(4) + +-- ISO-8859-1 string 4 -- +int(4) + +-- ISO-8859-1 string 5 -- +int(10) + +-- ISO-8859-1 string 6 -- +int(2) + +-- ISO-8859-1 string 7 -- +int(2) + +-- ISO-8859-1 string 8 -- +int(4) + +-- ISO-8859-1 string 9 -- +bool(false) + +-- ISO-8859-1 string 10 -- +int(2) + +-- ISO-8859-1 string 11 -- +int(2) + +-- ISO-8859-1 string 12 -- +int(4) + +-- ISO-8859-1 string 13 -- +bool(false) + +-- ISO-8859-1 string 14 -- +int(10) + +-- ISO-8859-1 string 15 -- +int(10) + +-- ISO-8859-1 string 16 -- +int(4) + +-- ISO-8859-1 string 17 -- +int(12) + +-- ISO-8859-1 string 18 -- +bool(false) + +-- Multibyte string 1 -- +int(0) + +-- Multibyte string 2 -- +bool(false) +Done diff --git a/ext/mbstring/tests/mb_stripos_error1.phpt b/ext/mbstring/tests/mb_stripos_error1.phpt new file mode 100644 index 0000000000..cad623366f --- /dev/null +++ b/ext/mbstring/tests/mb_stripos_error1.phpt @@ -0,0 +1,50 @@ +--TEST-- +Test mb_stripos() function : error conditions - Pass incorrect number of args +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +*** Testing mb_stripos() : error conditions *** + +-- Testing mb_stripos() function with more than expected no. of arguments -- + +Warning: mb_stripos() expects at most 4 parameters, 5 given in %s on line %d +bool(false) + +-- Testing mb_stripos() function with less than expected no. of arguments -- + +Warning: mb_stripos() expects at least 2 parameters, 1 given in %s on line %d +bool(false) +Done diff --git a/ext/mbstring/tests/mb_stripos_error2.phpt b/ext/mbstring/tests/mb_stripos_error2.phpt new file mode 100644 index 0000000000..75e0e6d556 --- /dev/null +++ b/ext/mbstring/tests/mb_stripos_error2.phpt @@ -0,0 +1,34 @@ +--TEST-- +Test mb_stripos() function : error conditions - Pass unknown encoding +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +*** Testing mb_stripos() : error conditions *** + +Warning: mb_stripos(): Unknown encoding "unknown-encoding" in %s on line %d +bool(false) +Done diff --git a/ext/mbstring/tests/mb_stripos_variation1.phpt b/ext/mbstring/tests/mb_stripos_variation1.phpt new file mode 100644 index 0000000000..411a939694 --- /dev/null +++ b/ext/mbstring/tests/mb_stripos_variation1.phpt @@ -0,0 +1,182 @@ +--TEST-- +Test mb_stripos() function : usage variations - pass different data types to $haystack arg +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +*** Testing mb_stripos() : usage variations *** + +-- Iteration 1 -- +bool(false) + +-- Iteration 2 -- +bool(false) + +-- Iteration 3 -- +bool(false) + +-- Iteration 4 -- +bool(false) + +-- Iteration 5 -- +bool(false) + +-- Iteration 6 -- +bool(false) + +-- Iteration 7 -- +bool(false) + +-- Iteration 8 -- +bool(false) + +-- Iteration 9 -- +bool(false) + +-- Iteration 10 -- +bool(false) + +-- Iteration 11 -- +bool(false) + +-- Iteration 12 -- +bool(false) + +-- Iteration 13 -- +bool(false) + +-- Iteration 14 -- +bool(false) + +-- Iteration 15 -- +bool(false) + +-- Iteration 16 -- +bool(false) + +-- Iteration 17 -- +bool(false) + +-- Iteration 18 -- +bool(false) + +-- Iteration 19 -- +bool(false) + +-- Iteration 20 -- +bool(false) + +-- Iteration 21 -- +bool(false) + +-- Iteration 22 -- +bool(false) + +-- Iteration 23 -- +bool(false) + +-- Iteration 24 -- + +Warning: mb_stripos() expects parameter 1 to be string, resource given in %s on line %d +bool(false) +Done diff --git a/ext/mbstring/tests/mb_stripos_variation2.phpt b/ext/mbstring/tests/mb_stripos_variation2.phpt new file mode 100644 index 0000000000..630ba2ed85 --- /dev/null +++ b/ext/mbstring/tests/mb_stripos_variation2.phpt @@ -0,0 +1,198 @@ +--TEST-- +Test mb_stripos() function : usage variations - pass different data types as $needle arg +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +*** Testing mb_stripos() : usage variations *** + +-- Iteration 1 -- +bool(false) + +-- Iteration 2 -- +bool(false) + +-- Iteration 3 -- +bool(false) + +-- Iteration 4 -- +bool(false) + +-- Iteration 5 -- +bool(false) + +-- Iteration 6 -- +bool(false) + +-- Iteration 7 -- +bool(false) + +-- Iteration 8 -- +bool(false) + +-- Iteration 9 -- +bool(false) + +-- Iteration 10 -- + +Warning: mb_stripos(): Empty delimiter. in %s on line %d +bool(false) + +-- Iteration 11 -- + +Warning: mb_stripos(): Empty delimiter. in %s on line %d +bool(false) + +-- Iteration 12 -- +bool(false) + +-- Iteration 13 -- + +Warning: mb_stripos(): Empty delimiter. in %s on line %d +bool(false) + +-- Iteration 14 -- +bool(false) + +-- Iteration 15 -- + +Warning: mb_stripos(): Empty delimiter. in %s on line %d +bool(false) + +-- Iteration 16 -- + +Warning: mb_stripos(): Empty delimiter. in %s on line %d +bool(false) + +-- Iteration 17 -- + +Warning: mb_stripos(): Empty delimiter. in %s on line %d +bool(false) + +-- Iteration 18 -- +int(0) + +-- Iteration 19 -- +int(0) + +-- Iteration 20 -- +bool(false) + +-- Iteration 21 -- +bool(false) + +-- Iteration 22 -- + +Warning: mb_stripos(): Empty delimiter. in %s on line %d +bool(false) + +-- Iteration 23 -- + +Warning: mb_stripos(): Empty delimiter. in %s on line %d +bool(false) + +-- Iteration 24 -- + +Warning: mb_stripos() expects parameter 2 to be string, resource given in %s on line %d +bool(false) +Done diff --git a/ext/mbstring/tests/mb_stripos_variation3.phpt b/ext/mbstring/tests/mb_stripos_variation3.phpt new file mode 100644 index 0000000000..0aada9ee70 --- /dev/null +++ b/ext/mbstring/tests/mb_stripos_variation3.phpt @@ -0,0 +1,202 @@ +--TEST-- +Test mb_stripos() function : usage variations - pass different data types as $offset arg +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +*** Testing mb_stripos() : usage variations *** + +-- Iteration 1 -- +int(8) + +-- Iteration 2 -- +int(8) + +-- Iteration 3 -- + +Warning: mb_stripos(): Offset not contained in string. in %s on line %d +bool(false) + +-- Iteration 4 -- + +Warning: mb_stripos(): Offset not contained in string. in %s on line %d +bool(false) + +-- Iteration 5 -- +bool(false) + +-- Iteration 6 -- + +Warning: mb_stripos(): Offset not contained in string. in %s on line %d +bool(false) + +-- Iteration 7 -- + +Warning: mb_stripos(): Offset not contained in string. in %s on line %d +bool(false) + +-- Iteration 8 -- +int(8) + +-- Iteration 9 -- +int(8) + +-- Iteration 10 -- +int(8) + +-- Iteration 11 -- +int(8) + +-- Iteration 12 -- +int(8) + +-- Iteration 13 -- +int(8) + +-- Iteration 14 -- +int(8) + +-- Iteration 15 -- +int(8) + +-- Iteration 16 -- + +Warning: mb_stripos() expects parameter 3 to be long, string given in %s on line %d +bool(false) + +-- Iteration 17 -- + +Warning: mb_stripos() expects parameter 3 to be long, string given in %s on line %d +bool(false) + +-- Iteration 18 -- + +Warning: mb_stripos() expects parameter 3 to be long, string given in %s on line %d +bool(false) + +-- Iteration 19 -- + +Warning: mb_stripos() expects parameter 3 to be long, string given in %s on line %d +bool(false) + +-- Iteration 20 -- + +Warning: mb_stripos() expects parameter 3 to be long, string given in %s on line %d +bool(false) + +-- Iteration 21 -- + +Warning: mb_stripos() expects parameter 3 to be long, object given in %s on line %d +bool(false) + +-- Iteration 22 -- +int(8) + +-- Iteration 23 -- +int(8) + +-- Iteration 24 -- + +Warning: mb_stripos() expects parameter 3 to be long, resource given in %s on line %d +bool(false) +Done diff --git a/ext/mbstring/tests/mb_stripos_variation4.phpt b/ext/mbstring/tests/mb_stripos_variation4.phpt new file mode 100644 index 0000000000..c62b2c3ff5 --- /dev/null +++ b/ext/mbstring/tests/mb_stripos_variation4.phpt @@ -0,0 +1,222 @@ +--TEST-- +Test mb_stripos() function : usage variations - pass different data types as $encoding arg +--SKIPIF-- + +--FILE-- + + +--EXPECTF-- +*** Testing mb_stripos() : usage variations *** + +-- Iteration 1 -- + +Warning: mb_stripos(): Unknown encoding "0" in %s on line %d +bool(false) + +-- Iteration 2 -- + +Warning: mb_stripos(): Unknown encoding "1" in %s on line %d +bool(false) + +-- Iteration 3 -- + +Warning: mb_stripos(): Unknown encoding "12345" in %s on line %d +bool(false) + +-- Iteration 4 -- + +Warning: mb_stripos(): Unknown encoding "-2345" in %s on line %d +bool(false) + +-- Iteration 5 -- + +Warning: mb_stripos(): Unknown encoding "10.5" in %s on line %d +bool(false) + +-- Iteration 6 -- + +Warning: mb_stripos(): Unknown encoding "-10.5" in %s on line %d +bool(false) + +-- Iteration 7 -- + +Warning: mb_stripos(): Unknown encoding "123456789000" in %s on line %d +bool(false) + +-- Iteration 8 -- + +Warning: mb_stripos(): Unknown encoding "1.23456789E-9" in %s on line %d +bool(false) + +-- Iteration 9 -- + +Warning: mb_stripos(): Unknown encoding "0.5" in %s on line %d +bool(false) + +-- Iteration 10 -- + +Warning: mb_stripos(): Unknown encoding "" in %s on line %d +bool(false) + +-- Iteration 11 -- + +Warning: mb_stripos(): Unknown encoding "" in %s on line %d +bool(false) + +-- Iteration 12 -- + +Warning: mb_stripos(): Unknown encoding "1" in %s on line %d +bool(false) + +-- Iteration 13 -- + +Warning: mb_stripos(): Unknown encoding "" in %s on line %d +bool(false) + +-- Iteration 14 -- + +Warning: mb_stripos(): Unknown encoding "1" in %s on line %d +bool(false) + +-- Iteration 15 -- + +Warning: mb_stripos(): Unknown encoding "" in %s on line %d +bool(false) + +-- Iteration 16 -- + +Warning: mb_stripos(): Unknown encoding "" in %s on line %d +bool(false) + +-- Iteration 17 -- + +Warning: mb_stripos(): Unknown encoding "" in %s on line %d +bool(false) + +-- Iteration 18 -- +int(7) + +-- Iteration 19 -- +int(7) + +-- Iteration 20 -- +int(7) + +-- Iteration 21 -- +int(7) + +-- Iteration 22 -- + +Warning: mb_stripos(): Unknown encoding "" in %s on line %d +bool(false) + +-- Iteration 23 -- + +Warning: mb_stripos(): Unknown encoding "" in %s on line %d +bool(false) + +-- Iteration 24 -- + +Warning: mb_stripos() expects parameter 4 to be string, resource given in %s on line %d +bool(false) +Done