From 2da796cabb3becf57b98ef1522e1cd8857c906d2 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 22 Aug 2023 14:44:13 +0900 Subject: [PATCH] dhcp: DUID-EN identifier has variable length Also make `array[0]` -> `array[]`. See RFC 8415, section 11.3. --- src/libsystemd-network/dhcp-identifier.c | 4 ++-- src/libsystemd-network/dhcp-identifier.h | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libsystemd-network/dhcp-identifier.c b/src/libsystemd-network/dhcp-identifier.c index b0572585e6..c905704ab5 100644 --- a/src/libsystemd-network/dhcp-identifier.c +++ b/src/libsystemd-network/dhcp-identifier.c @@ -114,9 +114,9 @@ int dhcp_identifier_set_duid_en(bool test_mode, struct duid *ret_duid, size_t *r /* a bit of snake-oil perhaps, but no need to expose the machine-id * directly; duid->en.id might not be aligned, so we need to copy */ hash = htole64(siphash24(&machine_id, sizeof(machine_id), HASH_KEY.bytes)); - memcpy(ret_duid->en.id, &hash, sizeof(ret_duid->en.id)); + memcpy(ret_duid->en.id, &hash, sizeof(hash)); - *ret_len = offsetof(struct duid, en.id) + sizeof(ret_duid->en.id); + *ret_len = offsetof(struct duid, en.id) + sizeof(hash); if (test_mode) assert_se(memcmp(ret_duid, (const uint8_t[]) { 0x00, 0x02, 0x00, 0x00, 0xab, 0x11, 0x61, 0x77, 0x40, 0xde, 0x13, 0x42, 0xc3, 0xa2 }, *ret_len) == 0); diff --git a/src/libsystemd-network/dhcp-identifier.h b/src/libsystemd-network/dhcp-identifier.h index 28acb2ca56..efb266ef80 100644 --- a/src/libsystemd-network/dhcp-identifier.h +++ b/src/libsystemd-network/dhcp-identifier.h @@ -35,17 +35,17 @@ struct duid { /* DUID_TYPE_LLT */ be16_t htype; be32_t time; - uint8_t haddr[0]; + uint8_t haddr[]; } _packed_ llt; struct { /* DUID_TYPE_EN */ be32_t pen; - uint8_t id[8]; + uint8_t id[]; } _packed_ en; struct { /* DUID_TYPE_LL */ be16_t htype; - uint8_t haddr[0]; + uint8_t haddr[]; } _packed_ ll; struct { /* DUID_TYPE_UUID */ -- 2.25.1