Skip to content

Commit beea989

Browse files
authored
[dhcp_relay] Check payload size to prevent buffer overflow in dhcpv6 option (#9740) (#10252)
1 parent af6ad54 commit beea989

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/dhcp6relay/src/relay.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -531,15 +531,18 @@ void relay_relay_forw(int sock, const uint8_t *msg, int32_t len, const ip6_hdr *
531531

532532
auto position = current_position + sizeof(struct dhcpv6_option);
533533
auto dhcpv6msg = parse_dhcpv6_hdr(position);
534-
535-
while ((current_position - msg) != len) {
534+
535+
while ((current_position - msg) < len) {
536536
auto option = parse_dhcpv6_opt(current_position, &tmp);
537537
current_position = tmp;
538+
if (current_position - msg > len || ntohs(option->option_length) > sizeof(buffer) - (current_buffer_position - buffer)) {
539+
break;
540+
}
538541
switch (ntohs(option->option_code)) {
539542
case OPTION_RELAY_MSG:
540543
memcpy(current_buffer_position, ((uint8_t *)option) + sizeof(struct dhcpv6_option), ntohs(option->option_length));
541544
current_buffer_position += ntohs(option->option_length);
542-
type = dhcpv6msg->msg_type;;
545+
type = dhcpv6msg->msg_type;
543546
break;
544547
default:
545548
break;

0 commit comments

Comments
 (0)