]> granicus.if.org Git - php/commitdiff
Making strstr() binary safe.
authorAndrey Hristov <andrey@php.net>
Wed, 2 Oct 2002 18:41:55 +0000 (18:41 +0000)
committerAndrey Hristov <andrey@php.net>
Wed, 2 Oct 2002 18:41:55 +0000 (18:41 +0000)
ext/standard/string.c

index a5dff3ed8febeb40fd5ce432352197eab1086fbd..540908db960333cb7c48713409b341c9f4c1f0b0 100644 (file)
@@ -1360,6 +1360,7 @@ PHP_FUNCTION(strstr)
        zval **haystack, **needle;
        char *found = NULL;
        char needle_char[2];
+       long found_offset;
        
        if (ZEND_NUM_ARGS() != 2 || 
                zend_get_parameters_ex(2, &haystack, &needle) == FAILURE) {
@@ -1387,7 +1388,8 @@ PHP_FUNCTION(strstr)
        }
 
        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;
        }