[Libwebsockets] [libwebsockets] #28: Crash due to file descriptor being accessed from union storing header data

Trac trac at libwebsockets.org
Fri May 3 16:29:36 CEST 2013


#28: Crash due to file descriptor being accessed from union storing header data
------------------------------------+--------------------------------
  Reporter:  simonwulf              |      Owner:  agreen
      Type:  defect                 |     Status:  new
  Priority:  critical               |  Milestone:
 Component:  libwebsockets library  |    Version:
Resolution:                         |   Keywords:  server union crash
------------------------------------+--------------------------------

Comment (by simonwulf):

 I followed your steps (open two chrome tabs, close one and ctrl-c) with a
 higher logging setting than before (logging everything except parse info)
 and noticed that it does output "calling back CLOSED", but the callback
 function does not seem to be called until Ctrl-C.

 The "INFO: callback_lws_mirror: LWS_CALLBACK_CLOSED" output was added by
 me as a response to the LWS_CALLBACK_CLOSED message. As you can see, this
 is only output after Ctrl-C and it's done once for the still open
 connection and once for the closed one.

 This is my entire output:

 [1367589369:0595] NOTICE: libwebsockets test server - (C) Copyright
 2010-2013 An
 dy Green <andy at warmcat.com> - licensed under LGPL2.1
 [1367589369:0605] NOTICE: Initial logging level 991
 [1367589369:0605] NOTICE: Library version: 1.3 86aa805
 [1367589369:0615] INFO:  LWS_MAX_HEADER_LEN: 1024
 [1367589369:0615] INFO:  LWS_MAX_PROTOCOLS: 5
 [1367589369:0615] INFO:  LWS_MAX_EXTENSIONS_ACTIVE: 3
 [1367589369:0625] INFO:  SPEC_LATEST_SUPPORTED: 13
 [1367589369:0625] INFO:  AWAITING_TIMEOUT: 5
 [1367589369:0635] INFO:  SYSTEM_RANDOM_FILEPATH: '/dev/urandom'
 [1367589369:0635] INFO:  LWS_MAX_ZLIB_CONN_BUFFER: 65536
 [1367589369:0665] NOTICE:  static allocation: 4436 + (12 x 30000 fds) =
 364436 b
 ytes
 [1367589369:0965] NOTICE:  canonical_hostname = 82TLQS1
 [1367589369:0965] NOTICE:  Compiled without SSL support
 [1367589369:0965] NOTICE:  per-conn mem: 124 + 1360 headers + protocol rx
 buf
 [1367589369:0975] INFO: insert_wsi_socket_into_fds: wsi=00585318,
 sock=420, fds
 pos=0
 [1367589369:0975] NOTICE:  Listening on port 7681
 [1367589369:0985] EXTENSION:   Extension: x-webkit-deflate-frame
 [1367589369:0985] EXTENSION:   Extension: deflate-frame

 (Server started, connecting in chrome)

 [1367589560:5235] DEBUG: accepted new conn  port 57859 on fd=424
 [1367589560:5245] INFO: insert_wsi_socket_into_fds: wsi=005853C0,
 sock=424, fds
 pos=1
 [1367589560:5245] DEBUG: accepted new conn  port 57860 on fd=428
 [1367589560:5255] INFO: insert_wsi_socket_into_fds: wsi=005859E8,
 sock=428, fds
 pos=2
 [1367589560:5265] INFO: HTTP request for '/'
 [1367589560:5285] NOTICE: choked before able to send whole file (post)
 [1367589560:5305] DEBUG: closing http fd 3
 [1367589560:5305] DEBUG: close: just_kill_connection
 [1367589560:5315] INFO: remove_wsi_socket_from_fds: wsi=005853C0,
 sock=424, fds
 pos=1
 [1367589560:5315] DEBUG: not calling back closed
 [1367589560:5905] DEBUG: accepted new conn  port 57861 on fd=424
 [1367589560:5905] INFO: insert_wsi_socket_into_fds: wsi=00585B08,
 sock=424, fds
 pos=2
     GET URI = /
     Host = localhost:7681
     Connection = Upgrade
     Protocol = dumb-increment-protocol
     Upgrade = websocket
     Origin = http://localhost:7681
     Key = AqrzWWJSMXiFuoNujqGOig==
     Version = 13
     Extensions = x-webkit-deflate-frame
 [1367589560:5935] EXTENSION: zlibs constructed
 HTTP/1.1 101 Switching Protocols
 Upgrade: WebSocket
 Connection: Upgrade
 Sec-WebSocket-Accept: lY7xMqE/Ky0WCevDmPHrXaaMPjI=
 Sec-WebSocket-Protocol: dumb-increment-protocol
 Sec-WebSocket-Extensions: x-webkit-deflate-frame

 [1367589560:5945] INFO: callback_dumb_increment: LWS_CALLBACK_ESTABLISHED
 [1367589560:5945] INFO: Allocating RX buffer 32
 [1367589560:5945] INFO: HTTP request for '/libwebsockets.org-logo.png'
 [1367589560:5945] INFO: LWS_CALLBACK_HTTP closing
 [1367589560:5945] INFO: closing connection at libwebsocket_read bail:
 [1367589560:5945] DEBUG: closing http fd 3
 [1367589560:5955] DEBUG: close: just_kill_connection
 [1367589560:5955] INFO: remove_wsi_socket_from_fds: wsi=005859E8,
 sock=428, fds
 pos=1
 [1367589560:5955] DEBUG: not calling back closed
 [1367589560:5955] DEBUG: accepted new conn  port 57862 on fd=428
 [1367589560:5955] INFO: insert_wsi_socket_into_fds: wsi=005859D0,
 sock=428, fds
 pos=2
     GET URI = /
     Host = localhost:7681
     Connection = Upgrade
     Protocol = lws-mirror-protocol
     Upgrade = websocket
     Origin = http://localhost:7681
     Key = 9+stxA2OnceXNC1xG2H0Ng==
     Version = 13
     Extensions = x-webkit-deflate-frame
 [1367589560:6095] EXTENSION: zlibs constructed
 HTTP/1.1 101 Switching Protocols
 Upgrade: WebSocket
 Connection: Upgrade
 Sec-WebSocket-Accept: NmpgowJLE0hj4HmM5eG1VWe1pJs=
 Sec-WebSocket-Protocol: lws-mirror-protocol
 Sec-WebSocket-Extensions: x-webkit-deflate-frame

 [1367589560:6105] INFO: callback_lws_mirror: LWS_CALLBACK_ESTABLISHED
 [1367589560:6105] INFO: Allocating RX buffer 150
 [1367589560:6605] DEBUG: deflate-frame ext TX did realloc to 4
 [1367589560:6605] DEBUG: deflate-frame ext TX did realloc to 4
 [1367589560:6615] DEBUG: deflate-frame ext TX did realloc to 4

 (Opening a second Chrome tab)

 [1367589673:5280] DEBUG: accepted new conn  port 57867 on fd=432
 [1367589673:5280] INFO: insert_wsi_socket_into_fds: wsi=005856C8,
 sock=432, fds
 pos=3
 [1367589673:5280] DEBUG: accepted new conn  port 57868 on fd=436
 [1367589673:5280] INFO: insert_wsi_socket_into_fds: wsi=00585770,
 sock=436, fds
 pos=4
 [1367589673:5660] INFO: HTTP request for '/'
 [1367589673:5670] NOTICE: choked before able to send whole file (post)
 [1367589673:5720] DEBUG: closing http fd 3
 [1367589673:5720] DEBUG: close: just_kill_connection
 [1367589673:5720] INFO: remove_wsi_socket_from_fds: wsi=005856C8,
 sock=432, fds
 pos=3
 [1367589673:5720] DEBUG: not calling back closed
 [1367589673:6330] DEBUG: accepted new conn  port 57869 on fd=432
 [1367589673:6330] INFO: insert_wsi_socket_into_fds: wsi=005856C8,
 sock=432, fds
 pos=4
 [1367589673:6340] INFO: HTTP request for '/libwebsockets.org-logo.png'
 [1367589673:6350] INFO: LWS_CALLBACK_HTTP closing
 [1367589673:6350] INFO: closing connection at libwebsocket_read bail:
 [1367589673:6350] DEBUG: closing http fd 3
 [1367589673:6350] DEBUG: close: just_kill_connection
 [1367589673:6350] INFO: remove_wsi_socket_from_fds: wsi=00585770,
 sock=436, fds
 pos=3
 [1367589673:6350] DEBUG: not calling back closed
     GET URI = /
     Host = localhost:7681
     Connection = Upgrade
     Protocol = dumb-increment-protocol
     Upgrade = websocket
     Origin = http://localhost:7681
     Key = e2qfhbyqFzq8GQFWFl/YfA==
     Version = 13
     Extensions = x-webkit-deflate-frame
 [1367589673:6880] EXTENSION: zlibs constructed
 HTTP/1.1 101 Switching Protocols
 Upgrade: WebSocket
 Connection: Upgrade
 Sec-WebSocket-Accept: tMjC2Bi6HucJ+ACd0ae439QGPN8=
 Sec-WebSocket-Protocol: dumb-increment-protocol
 Sec-WebSocket-Extensions: x-webkit-deflate-frame

 [1367589673:6890] INFO: callback_dumb_increment: LWS_CALLBACK_ESTABLISHED
 [1367589673:6890] INFO: Allocating RX buffer 32
 [1367589673:6910] DEBUG: accepted new conn  port 57870 on fd=436
 [1367589673:6920] INFO: insert_wsi_socket_into_fds: wsi=00585880,
 sock=436, fds
 pos=4
     GET URI = /
     Host = localhost:7681
     Connection = Upgrade
     Protocol = lws-mirror-protocol
     Upgrade = websocket
     Origin = http://localhost:7681
     Key = JovILNkGx7+vpxl654mi6g==
     Version = 13
     Extensions = x-webkit-deflate-frame
 [1367589673:6950] EXTENSION: zlibs constructed
 HTTP/1.1 101 Switching Protocols
 Upgrade: WebSocket
 Connection: Upgrade
 Sec-WebSocket-Accept: m9zJZpphTb0AueLxNpvlQemBNEc=
 Sec-WebSocket-Protocol: lws-mirror-protocol
 Sec-WebSocket-Extensions: x-webkit-deflate-frame

 [1367589673:6960] INFO: callback_lws_mirror: LWS_CALLBACK_ESTABLISHED
 [1367589673:6960] INFO: Allocating RX buffer 150
 [1367589673:7460] DEBUG: deflate-frame ext TX did realloc to 4
 [1367589673:7460] DEBUG: deflate-frame ext TX did realloc to 4
 [1367589673:7460] DEBUG: deflate-frame ext TX did realloc to 4

 (Closing the newly opened tab)

 [1367589737:9996] DEBUG: ERROR writing len 7 to skt -1
 [1367589737:9996] ERR: ERROR 4 writing to di socket
 [1367589737:9996] INFO: libwebsocket_service_fd: closing
 [1367589737:9996] DEBUG: close: just_kill_connection
 [1367589737:9996] INFO: remove_wsi_socket_from_fds: wsi=005856C8,
 sock=432, fds
 pos=3
 [1367589737:9996] DEBUG: calling back CLOSED
 [1367589737:9996] EXTENSION: zlibs destructed

 (Ctrl-C)

 [1367589863:2198] DEBUG: close: just_kill_connection
 [1367589863:2198] INFO: remove_wsi_socket_from_fds: wsi=00585318,
 sock=420, fds
 pos=0
 [1367589863:2198] DEBUG: not calling back closed
 [1367589863:2198] DEBUG: closing: shutdown returned 0
 [1367589863:2208] DEBUG: close: just_kill_connection
 [1367589863:2208] INFO: remove_wsi_socket_from_fds: wsi=00585880,
 sock=436, fds
 pos=0
 [1367589863:2208] DEBUG: calling back CLOSED
 [1367589863:2208] INFO: callback_lws_mirror: LWS_CALLBACK_CLOSED
 [1367589863:2208] EXTENSION: zlibs destructed
 [1367589863:2218] DEBUG: close: just_kill_connection
 [1367589863:2218] INFO: remove_wsi_socket_from_fds: wsi=005859D0,
 sock=428, fds
 pos=0
 [1367589863:2218] DEBUG: calling back CLOSED
 [1367589863:2218] INFO: callback_lws_mirror: LWS_CALLBACK_CLOSED
 [1367589863:2218] EXTENSION: zlibs destructed
 [1367589863:2218] DEBUG: close: just_kill_connection
 [1367589863:2218] DEBUG: calling back CLOSED
 [1367589863:2218] EXTENSION: zlibs destructed
 [1367589863:2228] NOTICE: mirror protocol cleaning up
 [1367589863:2228] NOTICE: libwebsockets-test-server exited cleanly

-- 
Ticket URL: <http://libwebsockets.org/trac/ticket/28#comment:10>
libwebsockets <http://libwebsockets.org>
libwebsockets C library



More information about the Libwebsockets mailing list