Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dhcp6relay/src/relay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ void client_packet_handler(uint8_t *buffer, ssize_t length, struct relay_config
const struct ip6_ext *ext_header;
do {
ext_header = (const struct ip6_ext *)current_position;
current_position += ext_header->ip6e_len;
current_position += (ext_header->ip6e_len + 1) * 8;
if((current_position == prev) ||
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

current_position wont be prev under current calculation

(current_position + sizeof(*ext_header) >= buffer_end)) {
return;
Expand Down
15 changes: 15 additions & 0 deletions dhcp6relay/test/mock_relay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,18 @@ TEST(relay, client_packet_handler) {
0x00, 0x00, 0x00, 0x19, 0x00, 0x0c, 0x27, 0xfe, 0x8f, 0x95, 0x00, 0x00, 0x0e, 0x10, 0x00, 0x00,
0x15, 0x18
};
// Packet with Hop-by-Hop extension header (ip6e_len=1 => 16 bytes per RFC 2460: (1+1)*8=16).
// Tests that the extension header pointer arithmetic is correct for nonzero ip6e_len.
// IPv6 next_header=0x00 (HbH), ext: nxt=0x11(UDP), len=0x01 -> advance 16 bytes -> UDP dst=547
uint8_t client_raw_solicit_with_hbh_extension[] = {
0x33, 0x33, 0x00, 0x01, 0x00, 0x02, 0x08, 0x00, 0x27, 0xfe, 0x8f, 0x95, 0x86, 0xdd, 0x60, 0x00,
0x00, 0x00, 0x00, 0x1c, 0x00, 0x01, 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00,
0x27, 0xff, 0xfe, 0xfe, 0x8f, 0x95, 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x11, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x22, 0x02, 0x23, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x10,
0x08, 0x74
};

uint8_t non_udp_with_externsion[] = {
0x33, 0x33, 0x00, 0x01, 0x00, 0x02, 0x08, 0x00, 0x27, 0xfe, 0x8f, 0x95, 0x86, 0xdd, 0x60, 0x00,
0x00, 0x00, 0x00, 0x44, 0x2c, 0x01, 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00,
Expand All @@ -745,6 +757,9 @@ TEST(relay, client_packet_handler) {
ASSERT_NO_THROW(client_packet_handler(client_raw_solicit_with_externsion, sizeof(client_raw_solicit_with_externsion), &config, ifname));

ASSERT_NO_THROW(client_packet_handler(non_udp_with_externsion, sizeof(non_udp_with_externsion), &config, ifname));

// nonzero ip6e_len=1: must advance (1+1)*8=16 bytes per RFC 2460, not 1 byte
ASSERT_NO_THROW(client_packet_handler(client_raw_solicit_with_hbh_extension, sizeof(client_raw_solicit_with_hbh_extension), &config, ifname));
}

MOCK_GLOBAL_FUNC6(recvfrom, ssize_t(int, void *, size_t, int, struct sockaddr *, socklen_t *));
Expand Down
Loading