From ca1533854552f073ce38172793c98772c88023e9 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Sun, 8 Dec 2013 21:26:52 +0800 Subject: [PATCH] interpret zero rx buffer size as default in http Reported by pystub https://github.com/warmcat/libwebsockets/pull/33#issuecomment-29578258 Signed-off-by: Andy Green --- lib/handshake.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/handshake.c b/lib/handshake.c index e853f57e..48b27672 100644 --- a/lib/handshake.c +++ b/lib/handshake.c @@ -74,8 +74,11 @@ http_postbody: wsi->u.http.post_buffer[wsi->u.http.body_index++] = *buf++; wsi->u.http.content_length_seen++; - if (wsi->u.http.body_index != - wsi->protocol->rx_buffer_size && + n = wsi->protocol->rx_buffer_size; + if (!n) + n = LWS_MAX_SOCKET_IO_BUF; + + if (wsi->u.http.body_index != n && wsi->u.http.content_length_seen != wsi->u.http.content_length) continue; @@ -231,7 +234,10 @@ http_postbody: if (wsi->u.http.content_length > 0) { wsi->u.http.body_index = 0; - wsi->u.http.post_buffer = malloc(wsi->protocol->rx_buffer_size); + n = wsi->protocol->rx_buffer_size; + if (!n) + n = LWS_MAX_SOCKET_IO_BUF; + wsi->u.http.post_buffer = malloc(n); if (!wsi->u.http.post_buffer) { lwsl_err("Unable to allocate post buffer\n"); n = -1;