From 983325bfdf83f42bdb1672a348414acc2fdd6df8 Mon Sep 17 00:00:00 2001 From: Ed Catmur Date: Thu, 19 Oct 2017 18:17:51 +0100 Subject: [PATCH] Ensure TCP::OptionTypes has 8-bit range (#259) 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`. --- include/tins/tcp.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/tins/tcp.h b/include/tins/tcp.h index a8f04ea..879da45 100644 --- a/include/tins/tcp.h +++ b/include/tins/tcp.h @@ -109,7 +109,9 @@ public: SACK_OK = 4, SACK = 5, TSOPT = 8, - ALTCHK = 14 + ALTCHK = 14, + RFC_EXPERIMENT_1 = 253, + RFC_EXPERIMENT_2 = 254 }; /**