diff --git a/lib/plat/freertos/private-lib-plat-freertos.h b/lib/plat/freertos/private-lib-plat-freertos.h index 089222392..4d7846910 100644 --- a/lib/plat/freertos/private-lib-plat-freertos.h +++ b/lib/plat/freertos/private-lib-plat-freertos.h @@ -119,7 +119,8 @@ struct lws; int insert_wsi(const struct lws_context *context, struct lws *wsi); -#define delete_from_fd(A,B) A->lws_lookup[B - lws_plat_socket_offset()] = 0 +#define delete_from_fd(A,B) assert((int)A->max_fds > B - lws_plat_socket_offset()); \ + A->lws_lookup[B - lws_plat_socket_offset()] = 0 #define LWS_PLAT_TIMER_TYPE TimerHandle_t #define LWS_PLAT_TIMER_CB(name, var) void name(TimerHandle_t var) diff --git a/lib/plat/optee/private-lib-plat-optee.h b/lib/plat/optee/private-lib-plat-optee.h index 9fb570fa0..7d2b351af 100644 --- a/lib/plat/optee/private-lib-plat-optee.h +++ b/lib/plat/optee/private-lib-plat-optee.h @@ -46,5 +46,6 @@ lws_plat_socket_offset()] == 0); \ A->lws_lookup[B->desc.sockfd - \ lws_plat_socket_offset()] = B -#define delete_from_fd(A,B) A->lws_lookup[B - lws_plat_socket_offset()] = 0 +#define delete_from_fd(A,B) assert((int)A->max_fds > B - lws_plat_socket_offset()); \ + A->lws_lookup[B - lws_plat_socket_offset()] = 0 diff --git a/lib/plat/unix/unix-fds.c b/lib/plat/unix/unix-fds.c index d6cd64d2e..6ef4ac3fc 100644 --- a/lib/plat/unix/unix-fds.c +++ b/lib/plat/unix/unix-fds.c @@ -174,8 +174,10 @@ delete_from_fd(const struct lws_context *context, int fd) struct lws **p, **done; if (!context->max_fds_unrelated_to_ulimit) { - if (context->lws_lookup) + if (context->lws_lookup) { + assert((int)context->max_fds > fd - lws_plat_socket_offset()); context->lws_lookup[fd - lws_plat_socket_offset()] = NULL; + } return; } diff --git a/minimal-examples/embedded/esp32/esp-c3dev/private-lib-plat-freertos.h b/minimal-examples/embedded/esp32/esp-c3dev/private-lib-plat-freertos.h index a81bbc055..25fc17e41 100644 --- a/minimal-examples/embedded/esp32/esp-c3dev/private-lib-plat-freertos.h +++ b/minimal-examples/embedded/esp32/esp-c3dev/private-lib-plat-freertos.h @@ -116,7 +116,8 @@ struct lws; int insert_wsi(const struct lws_context *context, struct lws *wsi); -#define delete_from_fd(A,B) A->lws_lookup[B - lws_plat_socket_offset()] = 0 +#define delete_from_fd(A,B) assert((int)A->max_fds > B - lws_plat_socket_offset()); \ + A->lws_lookup[B - lws_plat_socket_offset()] = 0 #define LWS_PLAT_TIMER_TYPE TimerHandle_t #define LWS_PLAT_TIMER_CB(name, var) void name(TimerHandle_t var)