Scanner problems

1) restore the scanner's original cursor position in case of
   insufficient input;
2) free the memories allocated for a new header in case of a failure.
(cherry picked from commit 7a571f513e801f071873f2627400461b04213b13)
This commit is contained in:
Peng 2013-09-02 14:38:04 -03:00 committed by Marcelo Roberto Jimenez
parent 8bcc4b41d1
commit 2c663643dd
2 changed files with 15 additions and 7 deletions

View File

@ -357,6 +357,12 @@ Version 1.8.0
Version 1.6.19
*******************************************************************************
2013-09-02 Peng <howtofly(at)gmail.com>
1) restore the scanner's original cursor position in case of
insufficient input;
2) free the memories allocated for a new header in case of a failure.
2013-08-13 Peng <howtofly(at)gmail.com>
Patch to fix behaviou when char is signed

View File

@ -1459,6 +1459,8 @@ parse_status_t parser_parse_headers(INOUT http_parser_t *parser)
/* check end of headers */
status = scanner_get_token(scanner, &token, &tok_type);
if (status != (parse_status_t)PARSE_OK) {
/* pushback tokens; useful only on INCOMPLETE error */
scanner->cursor = save_pos;
return status;
}
switch (tok_type) {
@ -1526,6 +1528,8 @@ parse_status_t parser_parse_headers(INOUT http_parser_t *parser)
if (membuffer_assign(&header->name_buf, token.buf, token.length) ||
membuffer_assign(&header->value, hdr_value.buf, hdr_value.length)) {
/* not enough mem */
membuffer_destroy(&header->value);
membuffer_destroy(&header->name_buf);
free(header);
parser->http_error_code = HTTP_INTERNAL_SERVER_ERROR;
return PARSE_FAILURE;
@ -1533,15 +1537,13 @@ parse_status_t parser_parse_headers(INOUT http_parser_t *parser)
header->name.buf = header->name_buf.buf;
header->name.length = header->name_buf.length;
header->name_id = header_id;
ListAddTail(&parser->msg.headers, header);
/*NNS: ret = dlist_append( &parser->msg.headers, header ); */
/** TODO: remove that? Yes as ret is not set anymore
if (ret == UPNP_E_OUTOF_MEMORY) {
parser->http_error_code =
HTTP_INTERNAL_SERVER_ERROR;
if (!ListAddTail(&parser->msg.headers, header)) {
membuffer_destroy(&header->value);
membuffer_destroy(&header->name_buf);
free(header);
parser->http_error_code = HTTP_INTERNAL_SERVER_ERROR;
return PARSE_FAILURE;
}
end of remove that? */
} else if (hdr_value.length > (size_t)0) {
/* append value to existing header */
/* append space */