Skip to content

Commit 56b0f18

Browse files
kellyyehpull[bot]
authored andcommitted
[dhcp_relay] Check payload size to prevent buffer overflow in dhcpv6 option (#9740)
1 parent a8ffc4f commit 56b0f18

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/dhcp6relay/src/relay.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -493,14 +493,17 @@ void relay_client(int sock, const uint8_t *msg, int32_t len, const ip6_hdr *ip_h
493493
auto position = current_position + sizeof(struct dhcpv6_option);
494494
auto dhcpv6msg = parse_dhcpv6_hdr(position);
495495

496-
while ((current_position - msg) != len) {
496+
while ((current_position - msg) < len) {
497497
auto option = parse_dhcpv6_opt(current_position, &tmp);
498498
current_position = tmp;
499+
if (current_position - msg > len || ntohs(option->option_length) > sizeof(buffer) - (current_buffer_position - buffer)) {
500+
break;
501+
}
499502
switch (ntohs(option->option_code)) {
500503
case OPTION_RELAY_MSG:
501504
memcpy(current_buffer_position, ((uint8_t *)option) + sizeof(struct dhcpv6_option), ntohs(option->option_length));
502505
current_buffer_position += ntohs(option->option_length);
503-
type = dhcpv6msg->msg_type;;
506+
type = dhcpv6msg->msg_type;
504507
break;
505508
default:
506509
break;

0 commit comments

Comments
 (0)