mirror of
https://github.com/php/php-src.git
synced 2025-08-20 09:24:05 +02:00
@- strpos() is now binary-safe. (Thies)
This commit is contained in:
parent
a9a5f24029
commit
db3cf21e55
1 changed files with 21 additions and 2 deletions
|
@ -34,6 +34,7 @@
|
||||||
#include "php_globals.h"
|
#include "php_globals.h"
|
||||||
|
|
||||||
int php_tag_find(char *tag, int len, char *set);
|
int php_tag_find(char *tag, int len, char *set);
|
||||||
|
static inline char *php_memnstr(char *haystack, char *needle, int needle_len, char *end);
|
||||||
|
|
||||||
/* this is read-only, so it's ok */
|
/* this is read-only, so it's ok */
|
||||||
static char hexconvtab[] = "0123456789abcdef";
|
static char hexconvtab[] = "0123456789abcdef";
|
||||||
|
@ -602,6 +603,8 @@ PHP_FUNCTION(strpos)
|
||||||
pval **haystack, **needle, **OFFSET;
|
pval **haystack, **needle, **OFFSET;
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
char *found = NULL;
|
char *found = NULL;
|
||||||
|
char *endp;
|
||||||
|
char *startp;
|
||||||
|
|
||||||
switch(ARG_COUNT(ht)) {
|
switch(ARG_COUNT(ht)) {
|
||||||
case 2:
|
case 2:
|
||||||
|
@ -615,25 +618,41 @@ PHP_FUNCTION(strpos)
|
||||||
}
|
}
|
||||||
convert_to_long_ex(OFFSET);
|
convert_to_long_ex(OFFSET);
|
||||||
offset = (*OFFSET)->value.lval;
|
offset = (*OFFSET)->value.lval;
|
||||||
|
if (offset < 0) {
|
||||||
|
php_error(E_WARNING,"offset not contained in string");
|
||||||
|
RETURN_FALSE;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
WRONG_PARAM_COUNT;
|
WRONG_PARAM_COUNT;
|
||||||
}
|
}
|
||||||
|
|
||||||
convert_to_string_ex(haystack);
|
convert_to_string_ex(haystack);
|
||||||
|
|
||||||
if (offset > (*haystack)->value.str.len) {
|
if (offset > (*haystack)->value.str.len) {
|
||||||
php_error(E_WARNING,"offset not contained in string");
|
php_error(E_WARNING,"offset not contained in string");
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
startp = (*haystack)->value.str.val;
|
||||||
|
startp+= offset;
|
||||||
|
|
||||||
|
endp = (*haystack)->value.str.val;
|
||||||
|
endp+= (*haystack)->value.str.len;
|
||||||
|
|
||||||
if ((*needle)->type == IS_STRING) {
|
if ((*needle)->type == IS_STRING) {
|
||||||
if ((*needle)->value.str.len==0) {
|
if ((*needle)->value.str.len==0) {
|
||||||
php_error(E_WARNING,"Empty delimiter");
|
php_error(E_WARNING,"Empty delimiter");
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
}
|
}
|
||||||
found = strstr((*haystack)->value.str.val+offset, (*needle)->value.str.val);
|
found = php_memnstr(startp, (*needle)->value.str.val, (*needle)->value.str.len, endp);
|
||||||
} else {
|
} else {
|
||||||
|
char buf;
|
||||||
|
|
||||||
convert_to_long_ex(needle);
|
convert_to_long_ex(needle);
|
||||||
found = strchr((*haystack)->value.str.val+offset, (char) (*needle)->value.lval);
|
buf = (char) (*needle)->value.lval;
|
||||||
|
|
||||||
|
found = php_memnstr(startp, &buf, 1, endp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (found) {
|
if (found) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue