X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=php_http_message_parser.c;h=3b55efbab7b295a9cd210fa57cb409769a3a97e6;hp=1bf2d295b08637fe2f63ddb72bfedc45c918cbbb;hb=refs%2Fheads%2Fv2.4.x;hpb=7887a2a98a2795120e93d54f33249a5f27e4a86e diff --git a/php_http_message_parser.c b/php_http_message_parser.c index 1bf2d29..3b55efb 100644 --- a/php_http_message_parser.c +++ b/php_http_message_parser.c @@ -124,17 +124,30 @@ php_http_message_parser_state_t php_http_message_parser_parse_stream(php_http_me if (!buf->data) { php_http_buffer_resize_ex(buf, 0x1000, 1, 0); } - while (!php_stream_eof(s)) { + while (1) { size_t justread = 0; #if DBG_PARSER fprintf(stderr, "#SP: %s (f:%u)\n", php_http_message_parser_state_name(state), flags); #endif + /* resize if needed */ + if (buf->free < 0x1000) { + php_http_buffer_resize_ex(buf, 0x1000, 1, 0); + } switch (state) { case PHP_HTTP_MESSAGE_PARSER_STATE_START: case PHP_HTTP_MESSAGE_PARSER_STATE_HEADER: case PHP_HTTP_MESSAGE_PARSER_STATE_HEADER_DONE: /* read line */ php_stream_get_line(s, buf->data + buf->used, buf->free, &justread); + /* if we fail reading a whole line, try a single char */ + if (!justread) { + int c = php_stream_getc(s); + + if (c != EOF) { + char s[1] = {c}; + justread = php_http_buffer_append(buf, s, 1); + } + } php_http_buffer_account(buf, justread); break; @@ -183,7 +196,7 @@ php_http_message_parser_state_t php_http_message_parser_parse_stream(php_http_me state = php_http_message_parser_parse(parser, buf, flags, message); } else if (php_stream_eof(s)) { return php_http_message_parser_parse(parser, buf, flags | PHP_HTTP_MESSAGE_PARSER_CLEANUP, message); - } else { + } else { return state; } }