Skip to content

Commit 581d583

Browse files
authored
Fixed handling of large sequence numbers
There was a bug in `compareTCPSeq` on 64bit architectures. When `seq1` or `seq2` were larger than `maxTCPSeq`, the result of `seq1 - (maxTCPSeq + seq2)` was supposed to be cast to int32 and result in a negative value but ended up positive. This caused packets to be dropped in line 314.
1 parent 52b113d commit 581d583

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

tcp_assembly.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -411,9 +411,9 @@ func (w *ReceiveWindow) expand() {
411411
// compare two tcp sequences, if seq1 is earlier, return num < 0, if seq1 == seq2, return 0, else return num > 0
412412
func compareTCPSeq(seq1, seq2 uint32) int {
413413
if seq1 < tcpSeqWindow && seq2 > maxTCPSeq-tcpSeqWindow {
414-
return int(seq1 + maxTCPSeq - seq2)
414+
return int(int32(seq1 + maxTCPSeq - seq2))
415415
} else if seq2 < tcpSeqWindow && seq1 > maxTCPSeq-tcpSeqWindow {
416-
return int(seq1 - (maxTCPSeq + seq2))
416+
return int(int32(seq1 - (maxTCPSeq + seq2)))
417417
}
418418
return int(int32(seq1 - seq2))
419419
}

0 commit comments

Comments
 (0)