X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=php_http_header_parser.c;h=5dfaeddfe8c9067c2a6393d82ed1a0d20b535d28;hp=f4dcf95e9e63828d9b43db7accd9024e28d8cf82;hb=1f37d09e4c7f55cf6f2c3c10ea3ec2424a482671;hpb=e438aa9ce944f8c8f175554d9aa66d152a47f780 diff --git a/php_http_header_parser.c b/php_http_header_parser.c index f4dcf95..5dfaedd 100644 --- a/php_http_header_parser.c +++ b/php_http_header_parser.c @@ -122,7 +122,7 @@ php_http_header_parser_state_t php_http_header_parser_parse(php_http_header_pars #endif switch (php_http_header_parser_state_pop(parser)) { case PHP_HTTP_HEADER_PARSER_STATE_FAILURE: - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse headers"); + php_error_docref(NULL, E_WARNING, "Failed to parse headers"); return php_http_header_parser_state_push(parser, 1, PHP_HTTP_HEADER_PARSER_STATE_FAILURE); case PHP_HTTP_HEADER_PARSER_STATE_START: { @@ -141,11 +141,14 @@ php_http_header_parser_state_t php_http_header_parser_parse(php_http_header_pars const char *colon, *eol_str = NULL; int eol_len = 0; + /* fix buffer here, so eol_str pointer doesn't become obsolete afterwards */ + php_http_buffer_fix(buffer); + if (buffer->data == (eol_str = php_http_locate_bin_eol(buffer->data, buffer->used, &eol_len))) { /* end of headers */ php_http_buffer_cut(buffer, 0, eol_len); php_http_header_parser_state_push(parser, 1, PHP_HTTP_HEADER_PARSER_STATE_DONE); - } else if (php_http_info_parse(&parser->info, php_http_buffer_fix(buffer)->data)) { + } else if (php_http_info_parse(&parser->info, buffer->data)) { /* new message starting with request/response line */ if (callback_func) { callback_func(callback_arg, &headers, &parser->info); @@ -162,7 +165,7 @@ php_http_header_parser_state_t php_http_header_parser_parse(php_http_header_pars valid_len = strspn(parser->_key.str, PHP_HTTP_HEADER_NAME_CHARS); if (valid_len != parser->_key.len) { - php_http_header_parser_error(valid_len, parser->_key.str, parser->_key.len, eol_str TSRMLS_CC); + php_http_header_parser_error(valid_len, parser->_key.str, parser->_key.len, eol_str); PTR_SET(parser->_key.str, NULL); return php_http_header_parser_state_push(parser, 1, PHP_HTTP_HEADER_PARSER_STATE_FAILURE); } @@ -171,8 +174,7 @@ php_http_header_parser_state_t php_http_header_parser_parse(php_http_header_pars php_http_header_parser_state_push(parser, 1, PHP_HTTP_HEADER_PARSER_STATE_VALUE); } else if (eol_str || (flags & PHP_HTTP_HEADER_PARSER_CLEANUP)) { /* neither reqeust/response line nor 'header:' string, or injected new line or NUL etc. */ - php_http_buffer_fix(buffer); - php_http_header_parser_error(strspn(buffer->data, PHP_HTTP_HEADER_NAME_CHARS), buffer->data, buffer->used, eol_str TSRMLS_CC); + php_http_header_parser_error(strspn(buffer->data, PHP_HTTP_HEADER_NAME_CHARS), buffer->data, buffer->used, eol_str); return php_http_header_parser_state_push(parser, 1, PHP_HTTP_HEADER_PARSER_STATE_FAILURE); } else { /* keep feeding */ @@ -245,7 +247,7 @@ php_http_header_parser_state_t php_http_header_parser_parse(php_http_header_pars /* check for truncation */ if (valid_len != parser->_val.len) { - php_http_header_parser_error(valid_len, parser->_val.str, parser->_val.len, NULL TSRMLS_CC); + php_http_header_parser_error(valid_len, parser->_val.str, parser->_val.len, NULL); PTR_SET(parser->_key.str, NULL); PTR_SET(parser->_val.str, NULL); @@ -285,7 +287,6 @@ php_http_header_parser_state_t php_http_header_parser_parse(php_http_header_pars php_http_header_parser_state_t php_http_header_parser_parse_stream(php_http_header_parser_t *parser, php_http_buffer_t *buf, php_stream *s, unsigned flags, HashTable *headers, php_http_info_callback_t callback_func, void *callback_arg) { php_http_header_parser_state_t state = PHP_HTTP_HEADER_PARSER_STATE_START; - TSRMLS_FETCH_FROM_CTX(parser->ts); if (!buf->data) { php_http_buffer_resize_ex(buf, 0x1000, 1, 0);