diff --git a/lib/core-net/dummy-callback.c b/lib/core-net/dummy-callback.c index 697e644f7..a45eee332 100644 --- a/lib/core-net/dummy-callback.c +++ b/lib/core-net/dummy-callback.c @@ -296,7 +296,8 @@ lws_callback_http_dummy(struct lws *wsi, enum lws_callback_reasons reason, case LWS_CALLBACK_HTTP_BODY: if (wsi->child_list) { lwsl_user("%s: LWS_CALLBACK_HTTP_BODY: stashing %d\n", __func__, (int)len); - lws_buflist_append_segment(&wsi->http.buflist_post_body, in, len); + if (lws_buflist_append_segment(&wsi->http.buflist_post_body, in, len) < 0) + return -1; lws_callback_on_writable(wsi->child_list); } break; diff --git a/lib/core-net/private.h b/lib/core-net/private.h index 351e32af1..11dbfb1cf 100644 --- a/lib/core-net/private.h +++ b/lib/core-net/private.h @@ -788,7 +788,7 @@ lws_hdr_simple_create(struct lws *wsi, enum lws_token_indexes h, const char *s); LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_ensure_user_space(struct lws *wsi); -LWS_EXTERN int +LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_change_pollfd(struct lws *wsi, int _and, int _or); #ifndef LWS_NO_SERVER diff --git a/lib/core-net/service.c b/lib/core-net/service.c index 96aaf2ab3..a14a303f8 100644 --- a/lib/core-net/service.c +++ b/lib/core-net/service.c @@ -204,7 +204,8 @@ user_service_go_again: vwsi->handling_pollout = 0; if (vwsi->leave_pollout_active) - lws_change_pollfd(wsi, 0, LWS_POLLOUT); + if (lws_change_pollfd(wsi, 0, LWS_POLLOUT)) + goto bail_die; return n; diff --git a/lib/roles/cgi/cgi-server.c b/lib/roles/cgi/cgi-server.c index ef2d26298..ea93815e3 100644 --- a/lib/roles/cgi/cgi-server.c +++ b/lib/roles/cgi/cgi-server.c @@ -184,9 +184,12 @@ lws_cgi(struct lws *wsi, const char * const *exec_array, wsi->child_list = cgi->stdwsi[n]; } - lws_change_pollfd(cgi->stdwsi[LWS_STDIN], LWS_POLLIN, LWS_POLLOUT); - lws_change_pollfd(cgi->stdwsi[LWS_STDOUT], LWS_POLLOUT, LWS_POLLIN); - lws_change_pollfd(cgi->stdwsi[LWS_STDERR], LWS_POLLOUT, LWS_POLLIN); + if (lws_change_pollfd(cgi->stdwsi[LWS_STDIN], LWS_POLLIN, LWS_POLLOUT)) + goto bail3; + if (lws_change_pollfd(cgi->stdwsi[LWS_STDOUT], LWS_POLLOUT, LWS_POLLIN)) + goto bail3; + if (lws_change_pollfd(cgi->stdwsi[LWS_STDERR], LWS_POLLOUT, LWS_POLLIN)) + goto bail3; lwsl_debug("%s: fds in %d, out %d, err %d\n", __func__, cgi->stdwsi[LWS_STDIN]->desc.sockfd, diff --git a/lib/roles/h1/ops-h1.c b/lib/roles/h1/ops-h1.c index aa6a62599..1b13100c3 100644 --- a/lib/roles/h1/ops-h1.c +++ b/lib/roles/h1/ops-h1.c @@ -354,7 +354,8 @@ lws_h1_server_socket_service(struct lws *wsi, struct lws_pollfd *pollfd) case 0: lwsl_info("%s: read 0 len a\n", __func__); wsi->seen_zero_length_recv = 1; - lws_change_pollfd(wsi, LWS_POLLIN, 0); + if (lws_change_pollfd(wsi, LWS_POLLIN, 0)) + goto fail; #if !defined(LWS_WITHOUT_EXTENSIONS) /* * autobahn requires us to win the race between close @@ -635,7 +636,8 @@ rops_handle_POLLIN_h1(struct lws_context_per_thread *pt, struct lws *wsi, * and turn off our POLLIN */ wsi->client_rx_avail = 1; - lws_change_pollfd(wsi, LWS_POLLIN, 0); + if (lws_change_pollfd(wsi, LWS_POLLIN, 0)) + return LWS_HPI_RET_PLEASE_CLOSE_ME; //lwsl_notice("calling back %s\n", wsi->protocol->name); diff --git a/lib/roles/h2/ops-h2.c b/lib/roles/h2/ops-h2.c index 183f81c04..06b7810ea 100644 --- a/lib/roles/h2/ops-h2.c +++ b/lib/roles/h2/ops-h2.c @@ -235,7 +235,8 @@ drain: * and turn off our POLLIN */ wsi->client_rx_avail = 1; - lws_change_pollfd(wsi, LWS_POLLIN, 0); + if (lws_change_pollfd(wsi, LWS_POLLIN, 0)) + return LWS_HPI_RET_PLEASE_CLOSE_ME; /* let user code know, he'll usually ask for writeable * callback and drain / re-enable it there @@ -1128,7 +1129,8 @@ next_child: wsi2a = wsi->h2.child_list; while (wsi2a) { if (wsi2a->h2.requested_POLLOUT) { - lws_change_pollfd(wsi, 0, LWS_POLLOUT); + if (lws_change_pollfd(wsi, 0, LWS_POLLOUT)) + return -1; break; } wsi2a = wsi2a->h2.sibling_list; diff --git a/lib/roles/http/client/client-handshake.c b/lib/roles/http/client/client-handshake.c index 8a5c6a709..7ee4717f3 100644 --- a/lib/roles/http/client/client-handshake.c +++ b/lib/roles/http/client/client-handshake.c @@ -637,7 +637,11 @@ ads_known: goto oom4; } - lws_change_pollfd(wsi, 0, LWS_POLLIN); + if (lws_change_pollfd(wsi, 0, LWS_POLLIN)) { + compatible_close(wsi->desc.sockfd); + cce = "change_pollfd failed"; + goto oom4; + } /* * past here, we can't simply free the structs as error diff --git a/lib/roles/http/compression/stream.c b/lib/roles/http/compression/stream.c index 617750ad4..7acb58e9b 100644 --- a/lib/roles/http/compression/stream.c +++ b/lib/roles/http/compression/stream.c @@ -158,8 +158,9 @@ lws_http_compression_transform(struct lws *wsi, unsigned char *buf, * and switch to trying to process the head. */ if (buf && len) { - lws_buflist_append_segment( - &ctx->buflist_comp, buf, len); + if (lws_buflist_append_segment( + &ctx->buflist_comp, buf, len) < 0) + return -1; lwsl_debug("%s: %p: adding %d to comp buflist\n", __func__,wsi, (int)len); } @@ -208,8 +209,9 @@ lws_http_compression_transform(struct lws *wsi, unsigned char *buf, * ...we were sending stuff from the caller directly and not * all of it got processed... stash on the buflist tail */ - lws_buflist_append_segment(&ctx->buflist_comp, - buf + ilen_iused, len - ilen_iused); + if (lws_buflist_append_segment(&ctx->buflist_comp, + buf + ilen_iused, len - ilen_iused) < 0) + return -1; lwsl_debug("%s: buffering %d unused comp input\n", __func__, (int)(len - ilen_iused)); diff --git a/lib/roles/raw-proxy/ops-raw-proxy.c b/lib/roles/raw-proxy/ops-raw-proxy.c index 6957744d5..9deb9c137 100644 --- a/lib/roles/raw-proxy/ops-raw-proxy.c +++ b/lib/roles/raw-proxy/ops-raw-proxy.c @@ -56,7 +56,8 @@ rops_handle_POLLIN_raw_proxy(struct lws_context_per_thread *pt, struct lws *wsi, case 0: lwsl_info("%s: read 0 len\n", __func__); wsi->seen_zero_length_recv = 1; - lws_change_pollfd(wsi, LWS_POLLIN, 0); + if (lws_change_pollfd(wsi, LWS_POLLIN, 0)) + goto fail; /* * we need to go to fail here, since it's the only diff --git a/lib/roles/raw-skt/ops-raw-skt.c b/lib/roles/raw-skt/ops-raw-skt.c index 939b2aefa..ff8140fbc 100644 --- a/lib/roles/raw-skt/ops-raw-skt.c +++ b/lib/roles/raw-skt/ops-raw-skt.c @@ -72,7 +72,8 @@ rops_handle_POLLIN_raw_skt(struct lws_context_per_thread *pt, struct lws *wsi, case 0: lwsl_info("%s: read 0 len\n", __func__); wsi->seen_zero_length_recv = 1; - lws_change_pollfd(wsi, LWS_POLLIN, 0); + if (lws_change_pollfd(wsi, LWS_POLLIN, 0)) + goto fail; /* * we need to go to fail here, since it's the only