diff options
Diffstat (limited to 'ext/standard/url.c')
-rw-r--r-- | ext/standard/url.c | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/ext/standard/url.c b/ext/standard/url.c index 20254de0c5..7763759bc1 100644 --- a/ext/standard/url.c +++ b/ext/standard/url.c @@ -91,6 +91,17 @@ PHPAPI php_url *php_url_parse(char const *str) return php_url_parse_ex(str, strlen(str)); } +static const char *binary_strcspn(const char *s, const char *e, const char *chars) { + while (*chars) { + const char *p = memchr(s, *chars, e - s); + if (p) { + e = p; + } + chars++; + } + return e; +} + /* {{{ php_url_parse */ PHPAPI php_url *php_url_parse_ex(char const *str, size_t length) @@ -109,7 +120,7 @@ PHPAPI php_url *php_url_parse_ex(char const *str, size_t length) while (p < e) { /* scheme = 1*[ lowalpha | digit | "+" | "-" | "." ] */ if (!isalpha(*p) && !isdigit(*p) && *p != '+' && *p != '.' && *p != '-') { - if (e + 1 < ue && e < s + strcspn(s, "?#")) { + if (e + 1 < ue && e < binary_strcspn(s, ue, "?#")) { goto parse_port; } else if (s + 1 < ue && *s == '/' && *(s + 1) == '/') { /* relative-scheme URL */ s += 2; @@ -209,18 +220,8 @@ PHPAPI php_url *php_url_parse_ex(char const *str, size_t length) goto just_path; } - parse_host: - /* Binary-safe strcspn(s, "/?#") */ - e = ue; - if ((p = memchr(s, '/', e - s))) { - e = p; - } - if ((p = memchr(s, '?', e - s))) { - e = p; - } - if ((p = memchr(s, '#', e - s))) { - e = p; - } +parse_host: + e = binary_strcspn(s, ue, "/?#"); /* check for login and password */ if ((p = zend_memrchr(s, '@', (e-s)))) { |