From: Andrey Hristov Date: Wed, 2 Oct 2002 18:58:09 +0000 (+0000) Subject: Making strrchr() binary safe. X-Git-Tag: MODERN_SYMMETRIC_SESSION_BEHAVIOUR_20021003~6 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=83a0f20381bfae0f678ff2c339d2a3e621c3f3d1;p=php Making strrchr() binary safe. Test case added. --- diff --git a/ext/standard/string.c b/ext/standard/string.c index 540908db96..f3d08a6bcb 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -1487,6 +1487,7 @@ PHP_FUNCTION(strrchr) { zval **haystack, **needle; char *found = NULL; + long found_offset; if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &haystack, &needle) == FAILURE) { @@ -1503,7 +1504,8 @@ PHP_FUNCTION(strrchr) } if (found) { - RETURN_STRING(found, 1); + found_offset = found - Z_STRVAL_PP(haystack); + RETURN_STRINGL(found, Z_STRLEN_PP(haystack) - found_offset, 1); } else { RETURN_FALSE; } diff --git a/ext/standard/tests/strings/002.phpt b/ext/standard/tests/strings/002.phpt new file mode 100644 index 0000000000..e13593d1af --- /dev/null +++ b/ext/standard/tests/strings/002.phpt @@ -0,0 +1,13 @@ +--TEST-- +Test whether strstr() and strrchr() are binary safe. +--POST-- +--GET-- +--FILE-- + +--EXPECT-- +int(18) +int(19) \ No newline at end of file