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

Ignore (possibly malformed) options after EOL (#281)

This commit is contained in:
Ed Catmur
2018-02-03 17:33:20 +00:00
committed by Matias Fontanini
parent 1038c6f7f3
commit 971fdf7d1c
2 changed files with 18 additions and 3 deletions

View File

@@ -81,7 +81,11 @@ TCP::TCP(const uint8_t* buffer, uint32_t total_sz) {
while (stream.pointer() < header_end) {
const OptionTypes option_type = (OptionTypes)stream.read<uint8_t>();
if (option_type <= NOP) {
if (option_type == EOL) {
stream.skip(header_end - stream.pointer());
break;
}
else if (option_type == NOP) {
#if TINS_IS_CXX11
add_option(option_type, 0);
#else
@@ -309,7 +313,7 @@ void TCP::write_serialization(uint8_t* buffer, uint32_t total_sz) {
if (options_size < total_options_size) {
const uint16_t padding = total_options_size - options_size;
stream.fill(padding, 1);
stream.fill(padding, 0);
}
uint32_t check = 0;

View File

@@ -13,7 +13,8 @@ using namespace Tins;
class TCPTest : public testing::Test {
public:
static const uint8_t expected_packet[], checksum_packet[],
partial_packet[];
partial_packet[],
malformed_option_after_eol_packet[];
void test_equals(const TCP& tcp1, const TCP& tcp2);
};
@@ -36,6 +37,11 @@ const uint8_t TCPTest::partial_packet[] = {
142, 210, 0, 80, 60, 158, 102, 111, 10, 2, 46, 161, 80, 24, 0, 229, 247, 192, 0, 0
};
const uint8_t TCPTest::malformed_option_after_eol_packet[] = {
127, 77, 79, 29, 241, 218, 229, 70, 95, 174, 209, 35, 96, 2, 113,
218, 0, 0, 31, 174, 0, 1, 2, 4
};
TEST_F(TCPTest, DefaultConstructor) {
TCP tcp;
@@ -271,6 +277,11 @@ TEST_F(TCPTest, SpoofedOptions) {
EXPECT_EQ(pdu.serialize().size(), pdu.size());
}
TEST_F(TCPTest, MalformedOptionAfterEOL) {
TCP tcp(malformed_option_after_eol_packet, sizeof(malformed_option_after_eol_packet));
EXPECT_EQ(0U, tcp.options().size());
}
TEST_F(TCPTest, RemoveOption) {
TCP tcp(22, 987);
uint8_t a[] = { 1,2,3,4,5,6 };