From ca771fb3bf90e190dee38bfc5b337c9d631238a6 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Mon, 4 Feb 2013 08:55:42 +0800 Subject: [PATCH] act on fatal parse problems Signed-off-by: Andy Green --- lib/client-parser.c | 4 ---- lib/client.c | 5 ++++- lib/handshake.c | 20 ++++++++++++-------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/lib/client-parser.c b/lib/client-parser.c index bb96e9b..3131f50 100644 --- a/lib/client-parser.c +++ b/lib/client-parser.c @@ -21,10 +21,6 @@ #include "private-libwebsockets.h" -#ifdef WIN32 -#include -#endif - int libwebsocket_client_rx_sm(struct libwebsocket *wsi, unsigned char c) { int n; diff --git a/lib/client.c b/lib/client.c index c92bc49..ef17ca8 100644 --- a/lib/client.c +++ b/lib/client.c @@ -288,7 +288,10 @@ int lws_client_socket_service(struct libwebsocket_context *context, struct libwe if (len < 0) goto bail3; - libwebsocket_parse(wsi, c); + if (libwebsocket_parse(wsi, c)) { + /* problems */ + goto bail3; + } } /* diff --git a/lib/handshake.c b/lib/handshake.c index 7cb2799..763aa4d 100644 --- a/lib/handshake.c +++ b/lib/handshake.c @@ -88,8 +88,10 @@ libwebsocket_read(struct libwebsocket_context *context, case LWS_CONNMODE_WS_CLIENT_WAITING_EXTENSION_CONNECT: case LWS_CONNMODE_WS_CLIENT: for (n = 0; n < len; n++) - libwebsocket_client_rx_sm(wsi, *buf++); - + if (libwebsocket_client_rx_sm(wsi, *buf++)) { + lwsl_info("libwebsocket_client_rx_sm failed\n"); + goto bail; + } return 0; default: break; @@ -99,13 +101,14 @@ libwebsocket_read(struct libwebsocket_context *context, /* LWS_CONNMODE_WS_SERVING */ for (n = 0; n < len; n++) - libwebsocket_parse(wsi, *buf++); + if (libwebsocket_parse(wsi, *buf++)) { + lwsl_info("libwebsocket_parse failed\n"); + goto bail; + } if (wsi->u.hdr.parser_state != WSI_PARSING_COMPLETE) break; - lwsl_parser("seem to be serving, mode is %d\n", wsi->mode); - lwsl_parser("libwebsocket_parse sees parsing complete\n"); /* is this websocket protocol or normal http 1.0? */ @@ -115,9 +118,10 @@ libwebsocket_read(struct libwebsocket_context *context, wsi->state = WSI_STATE_HTTP; if (wsi->protocol->callback) if (wsi->protocol->callback(context, wsi, - LWS_CALLBACK_HTTP, wsi->user_space, - wsi->utf8_token[WSI_TOKEN_GET_URI].token, - wsi->utf8_token[WSI_TOKEN_GET_URI].token_len)) { + LWS_CALLBACK_HTTP, + wsi->user_space, + wsi->utf8_token[WSI_TOKEN_GET_URI].token, + wsi->utf8_token[WSI_TOKEN_GET_URI].token_len)) { lwsl_info("LWS_CALLBACK_HTTP wanted to close\n"); goto bail; } -- 2.7.4