From 22d5b72b6479d360646501f101902d917b22f773 Mon Sep 17 00:00:00 2001 From: hidnplayr Date: Sat, 1 Nov 2014 18:27:28 +0000 Subject: [PATCH] Dont crash on socket_fork when out of memory. git-svn-id: svn://kolibrios.org@5155 a494cfbc-eb01-0410-851d-a64ba20cac60 --- kernel/trunk/network/socket.inc | 18 ++++++++++++++++-- kernel/trunk/network/tcp_input.inc | 4 ++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/kernel/trunk/network/socket.inc b/kernel/trunk/network/socket.inc index 554665125e..6819d42c9e 100644 --- a/kernel/trunk/network/socket.inc +++ b/kernel/trunk/network/socket.inc @@ -1223,10 +1223,13 @@ SOCKET_pair: lea eax, [eax + STREAM_SOCKET.rcv] call SOCKET_ring_create + test eax, eax + jz .nomem1 lea eax, [ebx + STREAM_SOCKET.rcv] call SOCKET_ring_create - pop eax + test eax, eax + jz .nomem2 ret @@ -1468,7 +1471,8 @@ SOCKET_input: ;-------------------------- ; -; eax = ptr to ring struct (just a buffer of the right size) +; IN: eax = ptr to ring struct (just a buffer of the right size) +; OUT: eax = unchanged / 0 on error ; align 4 SOCKET_ring_create: @@ -1479,6 +1483,8 @@ SOCKET_ring_create: push edx stdcall create_ring_buffer, SOCKET_MAXDATA, PG_SW pop edx + test eax, eax + jz .fail DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_ring_created: %x\n", eax @@ -1496,6 +1502,7 @@ SOCKET_ring_create: mov eax, esi pop esi + .fail: ret ;----------------------------------------------------------------- @@ -1539,6 +1546,7 @@ SOCKET_ring_write: jb @f sub edi, SOCKET_MAXDATA ; WRAP @@: + mov [eax + RING_BUFFER.write_ptr], edi pop edi @@ -1954,8 +1962,14 @@ SOCKET_free: jnz .no_tcp mov ebx, eax + cmp [ebx + STREAM_SOCKET.rcv.start_ptr], 0 + je @f stdcall kernel_free, [ebx + STREAM_SOCKET.rcv.start_ptr] + @@: + cmp [ebx + STREAM_SOCKET.snd.start_ptr], 0 + je @f stdcall kernel_free, [ebx + STREAM_SOCKET.snd.start_ptr] + @@: mov eax, ebx .no_tcp: diff --git a/kernel/trunk/network/tcp_input.inc b/kernel/trunk/network/tcp_input.inc index 49eba7dcde..7fdf03aeb2 100644 --- a/kernel/trunk/network/tcp_input.inc +++ b/kernel/trunk/network/tcp_input.inc @@ -1235,9 +1235,13 @@ align 4 lea eax, [ebx + STREAM_SOCKET.snd] call SOCKET_ring_create + test eax, eax + jz .drop lea eax, [ebx + STREAM_SOCKET.rcv] call SOCKET_ring_create + test eax, eax + jz .drop and [temp_bits], not TCP_BIT_DROPSOCKET