Skip to content

Commit cc9855b

Browse files
committed
net/dhcpv6: Improve option handling in dhcpv6 advertise
1 parent fe3a4e2 commit cc9855b

File tree

1 file changed

+16
-0
lines changed
  • sys/net/application_layer/dhcpv6

1 file changed

+16
-0
lines changed

sys/net/application_layer/dhcpv6/client.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,15 +654,27 @@ static int _preparse_advertise(uint8_t *adv, size_t len, uint8_t **buf)
654654
}
655655
switch (byteorder_ntohs(opt->type)) {
656656
case DHCPV6_OPT_CID:
657+
if (_opt_len(opt) < sizeof(dhcpv6_opt_duid_t)) {
658+
return -1;
659+
}
657660
cid = (dhcpv6_opt_duid_t *)opt;
658661
break;
659662
case DHCPV6_OPT_SID:
663+
if (_opt_len(opt) < sizeof(dhcpv6_opt_duid_t)) {
664+
return -1;
665+
}
660666
sid = (dhcpv6_opt_duid_t *)opt;
661667
break;
662668
case DHCPV6_OPT_STATUS:
669+
if (_opt_len(opt) < sizeof(dhcpv6_opt_status_t)) {
670+
return -1;
671+
}
663672
status = (dhcpv6_opt_status_t *)opt;
664673
break;
665674
case DHCPV6_OPT_PREF:
675+
if (_opt_len(opt) < sizeof(dhcpv6_opt_pref_t)) {
676+
return -1;
677+
}
666678
pref = (dhcpv6_opt_pref_t *)opt;
667679
break;
668680
default:
@@ -686,6 +698,10 @@ static int _preparse_advertise(uint8_t *adv, size_t len, uint8_t **buf)
686698
*buf = best_adv;
687699
}
688700
server.duid_len = byteorder_ntohs(sid->len);
701+
if (server.duid_len > DHCPV6_DUID_MAX_LEN) {
702+
DEBUG("DHCPv6 client: DUID length is too long.\n");
703+
return -1;
704+
}
689705
memcpy(server.duid.u8, sid->duid, server.duid_len);
690706
server.pref = pref_val;
691707
}

0 commit comments

Comments
 (0)