X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=php_http_header_parser.c;h=46551e21248959c67a7aa7d915885a6ec9d1e050;hp=cea2dbfa67e5a5e09e535327241cfe8f81032fce;hb=cc0b99e66062267073dff424fb9522f9c6933e28;hpb=e867316f1364f589eec67cc684703c874984430b diff --git a/php_http_header_parser.c b/php_http_header_parser.c index cea2dbf..46551e2 100644 --- a/php_http_header_parser.c +++ b/php_http_header_parser.c @@ -115,7 +115,7 @@ static void php_http_header_parser_error(size_t valid_len, char *str, size_t len efree(escaped_str); } -STATUS php_http_header_parser_parse(php_http_header_parser_t *parser, php_http_buffer_t *buffer, unsigned flags, HashTable *headers, php_http_info_callback_t callback_func, void *callback_arg) +php_http_header_parser_state_t php_http_header_parser_parse(php_http_header_parser_t *parser, php_http_buffer_t *buffer, unsigned flags, HashTable *headers, php_http_info_callback_t callback_func, void *callback_arg) { TSRMLS_FETCH_FROM_CTX(parser->ts); @@ -146,11 +146,14 @@ STATUS php_http_header_parser_parse(php_http_header_parser_t *parser, php_http_b 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 TSRMLS_CC)) { + } else if (php_http_info_parse(&parser->info, buffer->data TSRMLS_CC)) { /* new message starting with request/response line */ if (callback_func) { callback_func(callback_arg, &headers, &parser->info TSRMLS_CC); @@ -176,7 +179,6 @@ STATUS php_http_header_parser_parse(php_http_header_parser_t *parser, php_http_b 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); return php_http_header_parser_state_push(parser, 1, PHP_HTTP_HEADER_PARSER_STATE_FAILURE); } else { @@ -289,7 +291,7 @@ STATUS php_http_header_parser_parse(php_http_header_parser_t *parser, php_http_b 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_message_parser_state_t state = PHP_HTTP_MESSAGE_PARSER_STATE_START; + php_http_header_parser_state_t state = PHP_HTTP_HEADER_PARSER_STATE_START; TSRMLS_FETCH_FROM_CTX(parser->ts); if (!buf->data) {