From: David Galeano Date: Thu, 10 Jan 2013 02:20:01 +0000 (+0800) Subject: Fixed crash when HTTP requests method is not GET. X-Git-Tag: upstream/1.7.3~1185 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e0d0fd72b39a03ff9721f23e1b8368cf53a649c4;p=platform%2Fupstream%2Flibwebsockets.git Fixed crash when HTTP requests method is not GET. --- diff --git a/lib/parsers.c b/lib/parsers.c index a61c0e2..1564cd8 100644 --- a/lib/parsers.c +++ b/lib/parsers.c @@ -25,7 +25,7 @@ #include #endif -const struct lws_tokens lws_tokens[WSI_TOKEN_COUNT] = { +static const struct lws_tokens lws_tokens[WSI_TOKEN_COUNT] = { /* win32 can't do C99 */ @@ -88,6 +88,7 @@ int libwebsocket_parse(struct libwebsocket *wsi, unsigned char c) if (wsi->parser_state == WSI_TOKEN_GET_URI && c == ' ') { wsi->utf8_token[wsi->parser_state].token[ wsi->utf8_token[wsi->parser_state].token_len] = '\0'; +// debug("uri '%s'\n", wsi->utf8_token[wsi->parser_state].token); wsi->parser_state = WSI_TOKEN_SKIPPING; break; } @@ -210,11 +211,24 @@ int libwebsocket_parse(struct libwebsocket *wsi, unsigned char c) /* colon delimiter means we just don't know this name */ - if (wsi->parser_state == WSI_TOKEN_NAME_PART && c == ':') { - debug("skipping unknown header '%s'\n", - wsi->name_buffer); - wsi->parser_state = WSI_TOKEN_SKIPPING; - break; + if (wsi->parser_state == WSI_TOKEN_NAME_PART) { + if (c == ':') { + debug("skipping unknown header '%s'\n", + wsi->name_buffer); + wsi->parser_state = WSI_TOKEN_SKIPPING; + break; + } + + if (c == ' ' && + !wsi->utf8_token[WSI_TOKEN_GET_URI].token_len) { + debug("unknown method '%s'\n", + wsi->name_buffer); + wsi->parser_state = WSI_TOKEN_GET_URI; + wsi->current_alloc_len = LWS_INITIAL_HDR_ALLOC; + wsi->utf8_token[WSI_TOKEN_GET_URI].token = + malloc(wsi->current_alloc_len); + break; + } } if (wsi->parser_state != WSI_TOKEN_CHALLENGE)