From 6ae696a9568457aba24b3d3265cb9f9f38228eb4 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 16 May 2026 07:18:37 +0900 Subject: [PATCH] socket-util: extend the buffer in sockaddr_union to make it consistent with hw_addr_data Concerned by Claude: https://github.com/systemd/systemd/pull/42119#discussion_r3251133516 --- src/basic/basic-forward.h | 4 ++++ src/basic/ether-addr-util.h | 4 ---- src/basic/socket-util.c | 2 ++ src/basic/socket-util.h | 6 ++---- src/libsystemd-network/lldp-network.c | 1 + 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/basic/basic-forward.h b/src/basic/basic-forward.h index 396056a8e5..064af284a6 100644 --- a/src/basic/basic-forward.h +++ b/src/basic/basic-forward.h @@ -153,3 +153,7 @@ typedef struct SocketAddress SocketAddress; /* MAX_ERRNO is defined as 4095 in linux/err.h. We use the same value here. */ #define ERRNO_MAX 4095 + +/* This is MAX_ADDR_LEN as defined in linux/netdevice.h, but net/if_arp.h + * defines a macro of the same name with a much lower size. */ +#define HW_ADDR_MAX_SIZE 32 diff --git a/src/basic/ether-addr-util.h b/src/basic/ether-addr-util.h index 1d6e4cda7f..42b899e7eb 100644 --- a/src/basic/ether-addr-util.h +++ b/src/basic/ether-addr-util.h @@ -7,10 +7,6 @@ #include "basic-forward.h" -/* This is MAX_ADDR_LEN as defined in linux/netdevice.h, but net/if_arp.h - * defines a macro of the same name with a much lower size. */ -#define HW_ADDR_MAX_SIZE 32 - struct hw_addr_data { size_t length; union { diff --git a/src/basic/socket-util.c b/src/basic/socket-util.c index d53208f138..d84537bf44 100644 --- a/src/basic/socket-util.c +++ b/src/basic/socket-util.c @@ -3,6 +3,8 @@ #include #include #include +#include +#include #include #include #include diff --git a/src/basic/socket-util.h b/src/basic/socket-util.h index 208eb7ac07..1703a518e4 100644 --- a/src/basic/socket-util.h +++ b/src/basic/socket-util.h @@ -1,8 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include -#include #include #include #include @@ -29,8 +27,8 @@ union sockaddr_union { struct sockaddr_ll ll; struct sockaddr_vm vm; - /* Ensure there is enough space to store Infiniband addresses */ - uint8_t ll_buffer[offsetof(struct sockaddr_ll, sll_addr) + CONST_MAX(ETH_ALEN, INFINIBAND_ALEN)]; + /* Ensure there is enough space to store an arbitrary hardware address, e.g. Infiniband */ + uint8_t ll_buffer[offsetof(struct sockaddr_ll, sll_addr) + HW_ADDR_MAX_SIZE]; /* Ensure there is enough space after the AF_UNIX sun_path for one more NUL byte, just to be sure that the path * component is always followed by at least one NUL byte. */ diff --git a/src/libsystemd-network/lldp-network.c b/src/libsystemd-network/lldp-network.c index 53dd50c606..f8185a2802 100644 --- a/src/libsystemd-network/lldp-network.c +++ b/src/libsystemd-network/lldp-network.c @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include +#include #include "fd-util.h" #include "lldp-network.h"