1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-23 02:35:57 +01:00

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`.
This commit is contained in:
Ed Catmur
2017-10-19 18:17:51 +01:00
committed by Matias Fontanini
parent f4635a696e
commit 983325bfdf

View File

@@ -109,7 +109,9 @@ public:
SACK_OK = 4,
SACK = 5,
TSOPT = 8,
ALTCHK = 14
ALTCHK = 14,
RFC_EXPERIMENT_1 = 253,
RFC_EXPERIMENT_2 = 254
};
/**