Skip to content

Commit

Permalink
Bug appneta#451 Handle sequence overflows properly (appneta#515)
Browse files Browse the repository at this point in the history
* Bug appneta#451 Handle sequence overflows properly

Must convert to CPU order before sequence number math. Otherwise
overflows result in corrupt sequence numbers.

Also change to internal random number generator so that
big-endian and little-endian seeding is identical.

* Bug appneta#451 test signature file updates
  • Loading branch information
fklassen authored Oct 25, 2018
1 parent 9b46677 commit b0aaf9b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions src/tcpedit/rewrite_sequence.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ rewrite_seqs(tcpedit_t *tcpedit, tcp_hdr_t *tcp_hdr)
uint32_t newnum;

while (tcpedit->rewrite_sequence == 1)
tcpedit->rewrite_sequence = rand() * (4294967296 / RAND_MAX);
tcpedit->rewrite_sequence = tcpr_random(&tcpedit->rewrite_sequence);

newnum = tcp_hdr->th_seq + tcpedit->rewrite_sequence;
csum_replace4(&tcp_hdr->th_sum, tcp_hdr->th_seq, newnum);
tcp_hdr->th_seq = newnum;
newnum = ntohl(tcp_hdr->th_seq) + tcpedit->rewrite_sequence;
csum_replace4(&tcp_hdr->th_sum, tcp_hdr->th_seq, htonl(newnum));
tcp_hdr->th_seq = htonl(newnum);

/* first packet of 3-way handshake must have an ACK of zero - #450 */
if (!((tcp_hdr->th_flags & TH_SYN) && !(tcp_hdr->th_flags & TH_ACK))) {
newnum = tcp_hdr->th_ack + tcpedit->rewrite_sequence;
csum_replace4(&tcp_hdr->th_sum, tcp_hdr->th_ack, newnum);
tcp_hdr->th_ack = newnum;
newnum = ntohl(tcp_hdr->th_ack) + tcpedit->rewrite_sequence;
csum_replace4(&tcp_hdr->th_sum, tcp_hdr->th_ack, htonl(newnum));
tcp_hdr->th_ack = htonl(newnum);
}

return 0;
Expand Down
2 changes: 1 addition & 1 deletion test/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ if WORDS_BIGENDIAN
else
diff $(srcdir)/test2.$@ test.$@1 >> test.log 2>&1
endif
if [ $? ] ; then $(PRINTF) "\t\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t\t%s\n" "OK"; fi
if [ $? ] ; then $(PRINTF) "\t\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t%s\n" "OK"; fi

rewrite_endpoint:
$(PRINTF) "%s" "[tcprewrite] Endpoint test: "
Expand Down
Binary file modified test/test.rewrite_sequence
Binary file not shown.
Binary file modified test/test2.rewrite_sequence
Binary file not shown.

0 comments on commit b0aaf9b

Please sign in to comment.