Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dhcp_relay] fix data type in dhcp6relay, add protection in packet data parsing #9036

Merged
merged 6 commits into from
Oct 22, 2021
Merged
Changes from 3 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
8 changes: 7 additions & 1 deletion src/dhcp6relay/src/relay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,26 +515,32 @@ void relay_client(int sock, const uint8_t *msg, int32_t len, const ip6_hdr *ip_h
void callback(evutil_socket_t fd, short event, void *arg) {
struct relay_config *config = (struct relay_config *)arg;
static uint8_t message_buffer[4096];
uint32_t len = recv(config->filter, message_buffer, 4096, 0);
int32_t len = recv(config->filter, message_buffer, 4096, 0);
if (len <= 0) {
syslog(LOG_WARNING, "recv: Failed to receive data at filter socket\n");
saiarcot895 marked this conversation as resolved.
Show resolved Hide resolved
}

char* ptr = (char *)message_buffer;
const uint8_t *current_position = (uint8_t *)ptr;
const uint8_t *tmp = NULL;
const uint8_t *prev = NULL;

auto ether_header = parse_ether_frame(current_position, &tmp);
current_position = tmp;

auto ip_header = parse_ip6_hdr(current_position, &tmp);
current_position = tmp;

prev = current_position;
if (ip_header->ip6_ctlun.ip6_un1.ip6_un1_nxt != IPPROTO_UDP) {
const struct ip6_ext *ext_header;
do {
ext_header = (const struct ip6_ext *)current_position;
current_position += ext_header->ip6e_len;
yxieca marked this conversation as resolved.
Show resolved Hide resolved
if(current_position == prev) {
return;
}
prev = current_position;
}
while (ext_header->ip6e_nxt != IPPROTO_UDP);
}
Expand Down