From 18910c5920ea4e926b215eb61b4481e0f7d78fc6 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Wed, 9 Feb 2011 08:58:42 +0000 Subject: [PATCH] parse-and-reject-extensions-header.patch Signed-off-by: Andy Green --- lib/handshake.c | 5 +++++ lib/parsers.c | 2 ++ lib/private-libwebsockets.h | 3 +++ 3 files changed, 10 insertions(+) diff --git a/lib/handshake.c b/lib/handshake.c index 2a4ebb6..e42aae5 100644 --- a/lib/handshake.c +++ b/lib/handshake.c @@ -248,6 +248,11 @@ handshake_0405(struct libwebsocket *wsi) goto bail; } + if (wsi->utf8_token[WSI_TOKEN_EXTENSIONS].token_len) { + fprintf(stderr, "extensions not supported\n"); + goto bail; + } + if (wsi->utf8_token[WSI_TOKEN_KEY].token_len >= MAX_WEBSOCKET_04_KEY_LEN) { fprintf(stderr, "Client sent handshake key longer " diff --git a/lib/parsers.c b/lib/parsers.c index 7551f14..45a64f4 100644 --- a/lib/parsers.c +++ b/lib/parsers.c @@ -29,6 +29,7 @@ const struct lws_tokens lws_tokens[WSI_TOKEN_COUNT] = { [WSI_TOKEN_KEY2] = { "Sec-WebSocket-Key2:", 19 }, [WSI_TOKEN_PROTOCOL] = { "Sec-WebSocket-Protocol:", 23 }, [WSI_TOKEN_UPGRADE] = { "Upgrade:", 8 }, + [WSI_TOKEN_EXTENSIONS] = { "Sec-WebSocket-Extensions:", 25 }, [WSI_TOKEN_ORIGIN] = { "Origin:", 7 }, [WSI_TOKEN_DRAFT] = { "Sec-WebSocket-Draft:", 20 }, [WSI_TOKEN_CHALLENGE] = { "\x0d\x0a", 2 }, @@ -63,6 +64,7 @@ int libwebsocket_parse(struct libwebsocket *wsi, unsigned char c) case WSI_TOKEN_VERSION: case WSI_TOKEN_ACCEPT: case WSI_TOKEN_NONCE: + case WSI_TOKEN_EXTENSIONS: case WSI_TOKEN_HTTP: debug("WSI_TOKEN_(%d) '%c'\n", wsi->parser_state, c); diff --git a/lib/private-libwebsockets.h b/lib/private-libwebsockets.h index 14d4fb5..5c8de5d 100644 --- a/lib/private-libwebsockets.h +++ b/lib/private-libwebsockets.h @@ -115,6 +115,9 @@ enum lws_token_indexes { WSI_TOKEN_VERSION, WSI_TOKEN_SWORIGIN, + /* new for 05 */ + WSI_TOKEN_EXTENSIONS, + /* client receives these */ WSI_TOKEN_ACCEPT, WSI_TOKEN_NONCE, -- 2.7.4