From 4ffb8716cce3df75c8e2acfaa53c8e1489a52100 Mon Sep 17 00:00:00 2001 From: David Galeano Date: Thu, 10 Jan 2013 10:20:01 +0800 Subject: [PATCH] Fixed crash when HTTP requests method is not GET. --- lib/parsers.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) 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) -- 2.7.4