From 0e39e7f5c60bb880bb3dc53cb292cd6c33e9170d Mon Sep 17 00:00:00 2001 From: Andy Green Date: Tue, 13 Mar 2018 21:25:54 +0800 Subject: [PATCH] LWS_SERVER_OPTION_ALLOW_NON_SSL_ON_SSL_PORT: protect against zero length packet causing spin when deciding if tls or not tls https://github.com/warmcat/libwebsockets/pull/1206 --- lib/libwebsockets.c | 1 + lib/server/ssl-server.c | 12 +++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c index 41918d0b..3393f70e 100644 --- a/lib/libwebsockets.c +++ b/lib/libwebsockets.c @@ -751,6 +751,7 @@ just_kill_connection: /* libuv: no event available to guarantee completion */ if (!wsi->socket_is_permanently_unusable && lws_sockfd_valid(wsi->desc.sockfd) && + wsi->state != ((wsi->state & ~0x1f) | LWSS_SHUTDOWN) && !LWS_LIBUV_ENABLED(context)) { lws_change_pollfd(wsi, LWS_POLLOUT, LWS_POLLIN); wsi->state = (wsi->state & ~0x1f) | LWSS_SHUTDOWN; diff --git a/lib/server/ssl-server.c b/lib/server/ssl-server.c index 0a83941e..5a133814 100644 --- a/lib/server/ssl-server.c +++ b/lib/server/ssl-server.c @@ -218,14 +218,16 @@ lws_server_socket_service_ssl(struct lws *wsi, lws_sockfd_type accept_fd) if (lws_check_opt(context->options, LWS_SERVER_OPTION_REDIRECT_HTTP_TO_HTTPS)) wsi->redirect_to_https = 1; + lwsl_debug("accepted as non-ssl\n"); goto accepted; } - if (!n) /* - * connection is gone, or nothing to read - * if it's gone, we will timeout on - * PENDING_TIMEOUT_SSL_ACCEPT + if (!n) { + /* + * connection is gone, fail out */ - break; + lwsl_debug("PEEKed 0\n"); + goto fail; + } if (n < 0 && (LWS_ERRNO == LWS_EAGAIN || LWS_ERRNO == LWS_EWOULDBLOCK)) { /*