diff --git a/src/libsystemd-network/dhcp-client-id-internal.h b/src/libsystemd-network/dhcp-client-id-internal.h index f43d278cdd..2f51968758 100644 --- a/src/libsystemd-network/dhcp-client-id-internal.h +++ b/src/libsystemd-network/dhcp-client-id-internal.h @@ -32,7 +32,7 @@ typedef struct sd_dhcp_client_id { } _packed_ eth; struct { /* 2 - 254: ARP/Link-Layer (RFC 2132) */ - uint8_t haddr[0]; + uint8_t haddr[HW_ADDR_MAX_SIZE]; } _packed_ ll; struct { /* 255: Node-specific (RFC 4361) */ @@ -46,6 +46,8 @@ typedef struct sd_dhcp_client_id { }; } sd_dhcp_client_id; +assert_cc(sizeof_field(sd_dhcp_client_id, id) <= MAX_CLIENT_ID_LEN); + static inline bool client_id_size_is_valid(size_t size) { return size >= MIN_CLIENT_ID_LEN && size <= MAX_CLIENT_ID_LEN; } diff --git a/src/libsystemd-network/dhcp-duid-internal.h b/src/libsystemd-network/dhcp-duid-internal.h index 061786cd02..c2af1fa4dd 100644 --- a/src/libsystemd-network/dhcp-duid-internal.h +++ b/src/libsystemd-network/dhcp-duid-internal.h @@ -36,17 +36,19 @@ struct duid { /* DUID_TYPE_LLT */ be16_t htype; be32_t time; - uint8_t haddr[]; + uint8_t haddr[HW_ADDR_MAX_SIZE]; } _packed_ llt; struct { /* DUID_TYPE_EN */ be32_t pen; - uint8_t id[]; + /* The maximum length of vendor ID is not provided in RFC 8415, but we use 8 bytes. + * See https://datatracker.ietf.org/doc/html/rfc8415#section-11.3 */ + uint8_t id[8]; } _packed_ en; struct { /* DUID_TYPE_LL */ be16_t htype; - uint8_t haddr[]; + uint8_t haddr[HW_ADDR_MAX_SIZE]; } _packed_ ll; struct { /* DUID_TYPE_UUID */ @@ -56,6 +58,8 @@ struct duid { }; } _packed_; +assert_cc(sizeof(struct duid) == MAX_DUID_LEN); + typedef struct sd_dhcp_duid { size_t size; union {