From: Yu Watanabe Date: Wed, 4 Jun 2025 03:52:12 +0000 (+0900) Subject: sd-dhcp: explicitly set buffer size of each type X-Git-Tag: v258-rc1~365^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fda47cd92b1bb41bb23b6aa3abcab1cc4c6a51c0;p=thirdparty%2Fsystemd.git sd-dhcp: explicitly set buffer size of each type --- diff --git a/src/libsystemd-network/dhcp-client-id-internal.h b/src/libsystemd-network/dhcp-client-id-internal.h index f43d278cddd..2f51968758b 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 061786cd02d..c2af1fa4dd8 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 {