]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-dhcp: explicitly set buffer size of each type
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 4 Jun 2025 03:52:12 +0000 (12:52 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 4 Jun 2025 04:13:14 +0000 (13:13 +0900)
src/libsystemd-network/dhcp-client-id-internal.h
src/libsystemd-network/dhcp-duid-internal.h

index f43d278cdddd608f20cd1912aaab0d863167155e..2f51968758b6c10c6dcf14244f1a74b65be15d6f 100644 (file)
@@ -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;
 }
index 061786cd02d2f2b641cce0f728a40d907bda421a..c2af1fa4dd84414f17617140f25ca830e821a4fa 100644 (file)
@@ -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 {