Windows's "Socket.read" causes crash
velikoss opened this issue · comments
Velikiy Kirill commented
When net library use Socket.read
function on Windows, it causes the application to crash. This problem is not present on Linux nor macOS.
Steps to Reproduce
- Clone
c3-simple-http
. - Start the server on Windows.
- Send a GET request to the server.
Expected Behavior
The server should handle the GET request and respond appropriately.
Actual Behavior
The server crashes with a stack buffer overrun or stack overflow error.
Error Messages and Logs
STATUS_STACK_BUFFER_OVERRUN
STATUS_STACK_OVERFLOW
- The application stops working when a new connection is established.
Some Patches done to prevent this issue
-
The
accept
function intcp::accept
fails silently due to incorrect parameter initialization.- Adding
socket.ai_addrlen = socket.ai_addr_storage.len;
beforeos::accept
line fixes the issue
- Adding
-
Patches in
libc
extern fn isz recv(int sockFd, void* buf, usz nbyte, int flags) @if(!env::WIN32);
extern fn int recv(Win32_SOCKET s, char* buf, int len, int flags) @if(env::WIN32);
- Patched Socket.read
fn usz! Socket.read(&self, char[] bytes) @dynamic @if(env::WIN32)
{
int n = libc::recv((Win32_SOCKET)self.sock, bytes.ptr, bytes.len, 0);
if (n < 0) return NetError.READ_FAILED?;
return (usz)n;
}
Christoffer Lerno commented
Please try the latest master
, it has these patches and a little more.
Velikiy Kirill commented
Guess issue is fixed by now.