Hi All,
There is a race condition in both the tcp and tls code (in functions tcplistener and tlslistener) when accepting new connections. If new connections arrive in very short succession, and the second (or any further) accept() call returns before the previously created thread has actually started off, these threads operate on the wrong socket. (the pointer handed to the thread points to the local variable s in [tcp|tls]listener() which gets its new value before the thread could copy its value)
Proposed change: copy the variable to the heap and use this as argument to the new thread; also new thread is responsible for the memory if spawn is successful.
Additional side-fix: tcpreadtimeout() does a select() on a write-fd with the intention to wait for readable bytes. This was fixed in 1.6.3 for tls code, but not tcp.
Patch is attached.
Best regards, Fabian