From 08ebfa52378e4be57fcd65f02aa5d3f8dc8e8be9 Mon Sep 17 00:00:00 2001 From: Andrew Canaday Date: Wed, 2 Dec 2015 15:13:56 -0500 Subject: [PATCH] Handle pending SSL reads which would otherwise not trigger a POLLIN. service.c: Add handle_pending label and jump if more content after lws_server_socket_service ssl.c: set wsi->ssl = NULL on close (prevents potential segfault) --- lib/service.c | 8 +++++++- lib/ssl.c | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/service.c b/lib/service.c index 1571a198f..fb6ebb725 100644 --- a/lib/service.c +++ b/lib/service.c @@ -490,7 +490,12 @@ libwebsocket_service_fd(struct libwebsocket_context *context, n = lws_server_socket_service(context, wsi, pollfd); if (n < 0) goto close_and_handled; - goto handled; + if( lws_ssl_pending(wsi) ) { + goto handle_pending; + } + else { + goto handled; + }; case LWS_CONNMODE_WS_SERVING: case LWS_CONNMODE_WS_CLIENT: @@ -585,6 +590,7 @@ drain: eff_buf.token_len = 0; } while (more); +handle_pending: pending = lws_ssl_pending(wsi); if (pending) { pending = pending > sizeof(context->service_buffer)? diff --git a/lib/ssl.c b/lib/ssl.c index 571c9e1b8..6e9d33cdc 100644 --- a/lib/ssl.c +++ b/lib/ssl.c @@ -515,6 +515,7 @@ lws_ssl_close(struct libwebsocket *wsi) SSL_shutdown(wsi->ssl); compatible_close(n); SSL_free(wsi->ssl); + wsi->ssl = NULL; return 1; /* handled */ }