Skip to content

Commit 971fdf7

Browse files
ecatmurmfontanini
authored andcommitted
Ignore (possibly malformed) options after EOL (#281)
1 parent 1038c6f commit 971fdf7

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/tcp.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,11 @@ TCP::TCP(const uint8_t* buffer, uint32_t total_sz) {
8181

8282
while (stream.pointer() < header_end) {
8383
const OptionTypes option_type = (OptionTypes)stream.read<uint8_t>();
84-
if (option_type <= NOP) {
84+
if (option_type == EOL) {
85+
stream.skip(header_end - stream.pointer());
86+
break;
87+
}
88+
else if (option_type == NOP) {
8589
#if TINS_IS_CXX11
8690
add_option(option_type, 0);
8791
#else
@@ -309,7 +313,7 @@ void TCP::write_serialization(uint8_t* buffer, uint32_t total_sz) {
309313

310314
if (options_size < total_options_size) {
311315
const uint16_t padding = total_options_size - options_size;
312-
stream.fill(padding, 1);
316+
stream.fill(padding, 0);
313317
}
314318

315319
uint32_t check = 0;

tests/src/tcp_test.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ using namespace Tins;
1313
class TCPTest : public testing::Test {
1414
public:
1515
static const uint8_t expected_packet[], checksum_packet[],
16-
partial_packet[];
16+
partial_packet[],
17+
malformed_option_after_eol_packet[];
1718

1819
void test_equals(const TCP& tcp1, const TCP& tcp2);
1920
};
@@ -36,6 +37,11 @@ const uint8_t TCPTest::partial_packet[] = {
3637
142, 210, 0, 80, 60, 158, 102, 111, 10, 2, 46, 161, 80, 24, 0, 229, 247, 192, 0, 0
3738
};
3839

40+
const uint8_t TCPTest::malformed_option_after_eol_packet[] = {
41+
127, 77, 79, 29, 241, 218, 229, 70, 95, 174, 209, 35, 96, 2, 113,
42+
218, 0, 0, 31, 174, 0, 1, 2, 4
43+
};
44+
3945

4046
TEST_F(TCPTest, DefaultConstructor) {
4147
TCP tcp;
@@ -271,6 +277,11 @@ TEST_F(TCPTest, SpoofedOptions) {
271277
EXPECT_EQ(pdu.serialize().size(), pdu.size());
272278
}
273279

280+
TEST_F(TCPTest, MalformedOptionAfterEOL) {
281+
TCP tcp(malformed_option_after_eol_packet, sizeof(malformed_option_after_eol_packet));
282+
EXPECT_EQ(0U, tcp.options().size());
283+
}
284+
274285
TEST_F(TCPTest, RemoveOption) {
275286
TCP tcp(22, 987);
276287
uint8_t a[] = { 1,2,3,4,5,6 };

0 commit comments

Comments
 (0)