X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=src%2Fphp_http_url.c;h=8352608982e4ab769dfeccbdea4ae01f47d58f1d;hp=4009add52fc369a78c1741b9c2d12a2466bc1516;hb=74e7358add4c74d212b91d23e8600ef3c10d081e;hpb=a38d5303f4d542ff6ccf152bf3b01641edbdf200 diff --git a/src/php_http_url.c b/src/php_http_url.c index 4009add..8352608 100644 --- a/src/php_http_url.c +++ b/src/php_http_url.c @@ -1099,9 +1099,7 @@ static ZEND_RESULT_CODE parse_hostinfo(struct parse_state *state, const char *pt state->buffer[state->offset++] = *ptr; break; - case '!': case '$': case '&': case '\'': case '(': case ')': case '*': - case '+': case ',': case ';': case '=': /* sub-delims */ - case '-': case '.': case '_': case '~': /* unreserved */ + case '.': if (port || !label) { /* sort of a compromise, just ensure we don't end up * with a dot at the beginning or two consecutive dots @@ -1116,6 +1114,21 @@ static ZEND_RESULT_CODE parse_hostinfo(struct parse_state *state, const char *pt label = NULL; break; + case '-': + if (!label) { + /* sort of a compromise, just ensure we don't end up + * with a hyphen at the beginning + */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, + "Failed to parse %s; unexpected '%c' at pos %u in '%s'", + port ? "port" : "host", + (unsigned char) *ptr, (unsigned) (ptr - tmp), tmp); + return FAILURE; + } + /* no break */ + case '_': case '~': /* unreserved */ + case '!': case '$': case '&': case '\'': case '(': case ')': case '*': + case '+': case ',': case ';': case '=': /* sub-delims */ case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': @@ -1468,7 +1481,7 @@ static const char *parse_scheme(struct parse_state *state) case '7': case '8': case '9': case '+': case '-': case '.': if (state->ptr == tmp) { - return tmp; + goto softfail; } /* no break */ case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': @@ -1485,19 +1498,20 @@ static const char *parse_scheme(struct parse_state *state) default: if (!(mb = parse_mb(state, PARSE_SCHEME, state->ptr, state->end, tmp, 1))) { - /* soft fail; parse path next */ - return tmp; + goto softfail; } state->ptr += mb - 1; } } while (++state->ptr != state->end); +softfail: + state->offset = 0; return state->ptr = tmp; } php_http_url_t *php_http_url_parse(const char *str, size_t len, unsigned flags) { - size_t maxlen = 3 * len; + size_t maxlen = 3 * len + 8 /* null bytes for all components */; struct parse_state *state = ecalloc(1, sizeof(*state) + maxlen); state->end = str + len;