[Libwebsockets] Integer truncation in automatic setting of max_http_header_pool

Silas Parker skyhisi+libwebsockets at gmail.com
Tue Jun 19 11:12:55 CEST 2018


Hi Andy,

Just tracked down an issue that was preventing a custom libwebsockets
based server from working under Docker.

If max_http_header_pool (short int) is zero in the context creation
info, it takes the value from max_fds (int), and max_fds under Docker
was being set to 1048576 (0x100000), rather than 1024 like normal, so
it was being converted to 0 when assigned to max_http_header_pool.

I think the fix would be to either increase the width of
max_http_header_pool to an int, or to saturate the assignment. The
following diff is the saturation fix (assuming a short is 2 bytes):

diff --git a/lib/core/context.c b/lib/core/context.c
index 07f931c3..ebcd16af 100644
--- a/lib/core/context.c
+++ b/lib/core/context.c
@@ -1377,7 +1377,7 @@ lws_create_context(const struct
lws_context_creation_info *info)
                        context->max_http_header_pool =
                                        info->max_http_header_pool2;
                else
-                       context->max_http_header_pool = context->max_fds;
+                       context->max_http_header_pool =
context->max_fds > 32767 ? 32767 : context->max_fds;

        if (info->fd_limit_per_thread)
                context->fd_limit_per_thread = info->fd_limit_per_thread;

Thanks,
Silas


More information about the Libwebsockets mailing list