Skip to content

Commit 517d81a

Browse files
kellyyehyxieca
authored andcommitted
[dhcp_relay] fix data type in dhcp6relay, add protection in packet data parsing (#9036)
1 parent bb1bc59 commit 517d81a

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/dhcp6relay/src/relay.cpp

+11-4
Original file line numberDiff line numberDiff line change
@@ -515,29 +515,36 @@ void relay_client(int sock, const uint8_t *msg, int32_t len, const ip6_hdr *ip_h
515515
void callback(evutil_socket_t fd, short event, void *arg) {
516516
struct relay_config *config = (struct relay_config *)arg;
517517
static uint8_t message_buffer[4096];
518-
uint32_t len = recv(config->filter, message_buffer, 4096, 0);
518+
int32_t len = recv(config->filter, message_buffer, 4096, 0);
519519
if (len <= 0) {
520-
syslog(LOG_WARNING, "recv: Failed to receive data at filter socket\n");
520+
syslog(LOG_WARNING, "recv: Failed to receive data at filter socket: %s\n", strerror(errno));
521+
return;
521522
}
522523

523524
char* ptr = (char *)message_buffer;
524-
const uint8_t *current_position = (uint8_t *)ptr;
525+
const uint8_t *current_position = (uint8_t *)ptr;
525526
const uint8_t *tmp = NULL;
527+
const uint8_t *prev = NULL;
526528

527529
auto ether_header = parse_ether_frame(current_position, &tmp);
528530
current_position = tmp;
529531

530532
auto ip_header = parse_ip6_hdr(current_position, &tmp);
531533
current_position = tmp;
532534

535+
prev = current_position;
533536
if (ip_header->ip6_ctlun.ip6_un1.ip6_un1_nxt != IPPROTO_UDP) {
534537
const struct ip6_ext *ext_header;
535538
do {
536539
ext_header = (const struct ip6_ext *)current_position;
537540
current_position += ext_header->ip6e_len;
541+
if((current_position == prev) || (current_position >= (uint8_t *)ptr + sizeof(message_buffer))) {
542+
return;
543+
}
544+
prev = current_position;
538545
}
539546
while (ext_header->ip6e_nxt != IPPROTO_UDP);
540-
}
547+
}
541548

542549
auto udp_header = parse_udp(current_position, &tmp);
543550
current_position = tmp;

0 commit comments

Comments
 (0)