From 7c67634fecb7b04b092122e0e378ad21f03605dc Mon Sep 17 00:00:00 2001 From: Andrew Canaday Date: Mon, 7 Jul 2014 18:10:02 -0400 Subject: [PATCH] libwebsockets_read: update 'len' after lws_handshake_server invocation --- lib/handshake.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/handshake.c b/lib/handshake.c index 25dd3cc..dffd2d2 100644 --- a/lib/handshake.c +++ b/lib/handshake.c @@ -132,11 +132,18 @@ http_postbody: if (lws_handshake_client(wsi, &buf, len)) goto bail; - switch (lws_handshake_server(context, wsi, &buf, len)) { - case 1: - goto bail; - case 2: - goto http_postbody; + /* It's possible that we've exhausted our data already, but + * lws_handshake_server doesn't update len for us. Figure out how + * much was read, so that we can proceed appropriately: */ + { + unsigned char *last_char = buf; + switch (lws_handshake_server(context, wsi, &buf, len)) { + case 1: + goto bail; + case 2: + len -= (buf - last_char); + goto http_postbody; + } } break; -- 2.7.4