sd-dhcp6-client: fix off-by-two error in DUID length
The duid data passed by the client does not include the DUID type, but client->duid_len does account for the size of the DUID type.
This commit is contained in:
@@ -200,19 +200,19 @@ int sd_dhcp6_client_set_duid(sd_dhcp6_client *client, uint16_t type, uint8_t *du
|
|||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case DHCP6_DUID_LLT:
|
case DHCP6_DUID_LLT:
|
||||||
if (duid_len <= sizeof(client->duid.llt))
|
if (duid_len <= sizeof(client->duid.llt) - 2)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
break;
|
break;
|
||||||
case DHCP6_DUID_EN:
|
case DHCP6_DUID_EN:
|
||||||
if (duid_len != sizeof(client->duid.en))
|
if (duid_len != sizeof(client->duid.en) - 2)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
break;
|
break;
|
||||||
case DHCP6_DUID_LL:
|
case DHCP6_DUID_LL:
|
||||||
if (duid_len <= sizeof(client->duid.ll))
|
if (duid_len <= sizeof(client->duid.ll) - 2)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
break;
|
break;
|
||||||
case DHCP6_DUID_UUID:
|
case DHCP6_DUID_UUID:
|
||||||
if (duid_len != sizeof(client->duid.uuid))
|
if (duid_len != sizeof(client->duid.uuid) - 2)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -222,7 +222,7 @@ int sd_dhcp6_client_set_duid(sd_dhcp6_client *client, uint16_t type, uint8_t *du
|
|||||||
|
|
||||||
client->duid.raw.type = htobe16(type);
|
client->duid.raw.type = htobe16(type);
|
||||||
memcpy(&client->duid.raw.data, duid, duid_len);
|
memcpy(&client->duid.raw.data, duid, duid_len);
|
||||||
client->duid_len = duid_len;
|
client->duid_len = duid_len + 2; /* +2 for sizeof(type) */
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user