fix edge cases with @
[m6w6/ext-http] / php_http_url.c
index 09f94ec30494a549215a62f6e668c6d12cfa7fff..1f06271f9527183f12c9c5c2a46506b14a674b74 100644 (file)
@@ -528,7 +528,7 @@ static STATUS parse_hostinfo(php_http_url_t *url, const char *ptr)
                case ':':
                        if (port) {
                                php_error_docref(NULL TSRMLS_CC, E_WARNING,
-                                               "Failed to parse port; duplicate ':' at pos %u in '%s'",
+                                               "Failed to parse port; unexpected ':' at pos %u in '%s'",
                                                (unsigned) (ptr - tmp), tmp);
                                return FAILURE;
                        }
@@ -625,12 +625,19 @@ static STATUS parse_hostinfo(php_http_url_t *url, const char *ptr)
 
 static const char *parse_authority(php_http_url_t *url)
 {
-       const char *tmp = url->ptr;
+       const char *tmp = url->ptr, *host = NULL;
 
        do {
                switch (*url->ptr) {
                case '@':
                        /* userinfo delimiter */
+                       if (host) {
+                               TSRMLS_FETCH_FROM_CTX(url->ts);
+                               php_error_docref(NULL TSRMLS_CC, E_WARNING,
+                                               "Failed to parse userinfo; unexpected '@'");
+                               return NULL;
+                       }
+                       host = url->ptr + 1;
                        if (tmp != url->ptr && SUCCESS != parse_userinfo(url, tmp)) {
                                return NULL;
                        }
@@ -726,8 +733,8 @@ static const char *parse_query(php_http_url_t *url)
        const char *tmp = url->ptr + !!*url->ptr;
        TSRMLS_FETCH_FROM_CTX(url->ts);
 
-       /* is there actually a query to parse ? */
-       if (!*url->ptr && *url->ptr != '?') {
+       /* is there actually a query to parse? */
+       if (*url->ptr != '?') {
                return url->ptr;
        }
 
@@ -790,8 +797,8 @@ static const char *parse_fragment(php_http_url_t *url)
        const char *tmp;
        TSRMLS_FETCH_FROM_CTX(url->ts);
 
-       /* is there actually a fragment to parse */
-       if (!*url->ptr && *url->ptr != '#') {
+       /* is there actually a fragment to parse? */
+       if (*url->ptr != '#') {
                return url->ptr;
        }