[Libwebsockets] seg fault in lib using test-server

Andy Green andy at warmcat.com
Thu Feb 4 11:52:07 CET 2016



On February 4, 2016 4:19:45 PM GMT+07:00, "Björn Grunwald" <b.grunwald at abberior-instruments.com> wrote:
>Hi,
>
>I am using libwebsockets on a National Instruments sbRIO module (SoM
>with a Xilinx Zynq dual core ARM/FPGA). For a start I use the

I'm very familiar with Zynq... but not the NI stuff.

>test-server to evaluate the performance of websockets for the target
>application.
>
>When the test-server sends the big jpg picture via http with a click on
>the link in the test page, it is displayed properly in the browser. But
>I observe a seg fault of test-server just after the successful transfer
>of the image. Everything else on the test page works fine.

Hm.

>I tracked the problem down to wsi->u.hdr.ah being NULL in
>lws_reset_header_table. Now I patched parsers.c to prevent the seg
>fault.
>
>The patch seems to work, but I am not sure if it violates the idea
>behind using lws_reset_header_table() and lws_free_header_table() in

The presumption of calling lws_reset_header_table() is certainly that you have a live ah to reset.  So it could better have assert(wsi->u.hdr.ah) since something's busted if we got the idea to reset something we don't have.

>lws_http_transaction_completed(). Is it better to use
>lws_free_header_table() instead? This also works. But I am not sure why
>wsi->u.hdr.ah is NULL actually. Is this the bug perhaps?

Yes I think so.

Are you using current HEAD?  Basically when the http request completes, he should still have the ah, and he makes a decision whether to free it if no new header already waiting, or keep it and reset it if more data is already arrived (ie, headers for the next pipelined http transaction).

>Is there anything else I can do to analyse the problem?

It's possible this is already fixed if you master branch is more than 4 days old.

https://github.com/warmcat/libwebsockets/commit/4019aab8da469eab328a66c2e1ab0a059458f7b6

-Andy

>Regards,
>
>                               Björn
>
>Technical stuff:
>
>The stack trace looks like this:
>Thread [1] 2541 [core: 0] (Suspended : Signal : SIGSEGV:Segmentation
>fault)
>       0xb6d2ac20
>       lws_reset_header_table() at 0xf344
>       lws_http_transaction_completed() at 0x16b5c
>       callback_http() at test-server-http.c:466 0xbca4
>       user_callback_handle_rxflow() at 0xcb24
>       lws_server_socket_service() at 0x16f34
>       lws_service_fd_tsi() at 0xdf30
>       lws_plat_service_tsi() at 0x15934
>       main() at test-server.c:373 0xa934
>
>working patch:
>--- a/lib/parsers.c
>+++ b/lib/parsers.c
>@@ -64,10 +64,13 @@ void
>lws_reset_header_table(struct lws *wsi)
>{
>               lwsl_err("%s: wsi %p\n", __func__, wsi);
>-              /* init the ah to reflect no headers or data have
>appeared yet */
>-              memset(wsi->u.hdr.ah->frag_index, 0,
>sizeof(wsi->u.hdr.ah->frag_index));
>-              wsi->u.hdr.ah->nfrag = 0;
>-              wsi->u.hdr.ah->pos = 0;
>+             if (wsi->u.hdr.ah)
>+             {
>+                             /* init the ah to reflect no headers or
>data have appeared yet */
>+                             memset(wsi->u.hdr.ah->frag_index, 0,
>sizeof(wsi->u.hdr.ah->frag_index));
>+                             wsi->u.hdr.ah->nfrag = 0;
>+                             wsi->u.hdr.ah->pos = 0;
>+             }
>}
>
>libwebsockets has been cross-compiled by me on Windows 7 with this
>cmake command line:
>cmake .. -G "MinGW Makefiles" \
>    -DCMAKE_SYSTEM_NAME=Linux \
>-DCMAKE_C_COMPILER="C:/Program Files (x86)/National
>Instruments/Eclipse/14.0/arm/sysroots/i686-nilrtsdk-mingw32/usr/bin/armv7a-vfp-neon-nilrt-linux-gnueabi/arm-nilrt-linux-gnueabi-gcc.exe"
>\
>    -DCMAKE_MAKE_PROGRAM="C:/UnixUtils/make.exe" \
>    -DWITHOUT-EXTENSIONS=1 \
>    -DWITH-SSL=0 \
>    -Wno-dev \
>    -DZLIB_ROOT="C:/libs/zlib" \
>    -DOPENSSL_ROOT_DIR="C:/libs/ssl"
>
>test-server has been cross-compiled in Eclipse using the same
>toolchain.
>
>The browser is Firefox 43 on Windows.
>
>
>------------------------------------------------------------------------
>
>_______________________________________________
>Libwebsockets mailing list
>Libwebsockets at ml.libwebsockets.org
>http://ml.libwebsockets.org/mailman/listinfo/libwebsockets




More information about the Libwebsockets mailing list