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
This commit is contained in:
Andy Green 2018-03-13 21:25:54 +08:00
parent 1b5d772c4a
commit 0e39e7f5c6
2 changed files with 8 additions and 5 deletions

View file

@ -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;

View file

@ -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)) {
/*