Skip to content

Commit

Permalink
Ensure TCP::OptionTypes has 8-bit range (mfontanini#259)
Browse files Browse the repository at this point in the history
When reading TCP packets with esoteric (or corrupt) values for option types, the asan fsanitize=enum will trigger if the read value is not in range of the enum. The range of a classic (pre-C++11) enum with no negative enumerators is determined by the highest bit set in any of its enumerators, so if `TCP::OptionTypes` has highest enumerator `ALTCHK  = 14` it cannot take values above 15.

Define enumerators (per IANA) with bit 7 set to ensure that `TCP::OptionTypes` can take any 8-bit value.

An alternative (C++11 only) would be to give `TCP::OptionTypes` underlying type `uint8_t`.
  • Loading branch information
ecatmur authored and mfontanini committed Oct 19, 2017
1 parent f4635a6 commit 983325b
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion include/tins/tcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ class TINS_API TCP : public PDU {
SACK_OK = 4,
SACK = 5,
TSOPT = 8,
ALTCHK = 14
ALTCHK = 14,
RFC_EXPERIMENT_1 = 253,
RFC_EXPERIMENT_2 = 254
};

/**
Expand Down

0 comments on commit 983325b

Please sign in to comment.