Skip to content

Commit

Permalink
network-stack: Fix racy TCP data loss upon peer closure
Browse files Browse the repository at this point in the history
Where the closure resulted in us letting go of the PCB, and the recv()
logic would return early because the PCB was gone. At that point there
might still be data left in the RX buffer, but the application wouldn't
see it.
  • Loading branch information
oleavr committed Oct 3, 2024
1 parent 66099c7 commit 3238e22
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/fruity/network-stack.vala
Original file line number Diff line number Diff line change
Expand Up @@ -601,9 +601,6 @@ namespace Frida.Fruity {
ssize_t n = 0;

netstack.perform_on_lwip_thread (() => {
if (pcb == null)
return OK;

lock (state) {
n = ssize_t.min (buffer.length, rx_buf.len);
if (n == 0)
Expand All @@ -612,6 +609,9 @@ namespace Frida.Fruity {
rx_buf.remove_range (0, (uint) n);
}

if (pcb == null)
return OK;

size_t remainder = n;
while (remainder != 0) {
uint16 chunk = (uint16) size_t.min (remainder, uint16.MAX);
Expand Down

0 comments on commit 3238e22

Please sign in to comment.