From: Yu Watanabe Date: Fri, 15 May 2026 22:18:37 +0000 (+0900) Subject: socket-util: extend the buffer in sockaddr_union to make it consistent with hw_addr_data X-Git-Tag: v261-rc1~139 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6ae696a9568457aba24b3d3265cb9f9f38228eb4;p=thirdparty%2Fsystemd.git 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 --- diff --git a/src/basic/basic-forward.h b/src/basic/basic-forward.h index 396056a8e55..064af284a65 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 1d6e4cda7f0..42b899e7ebc 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 d53208f1389..d84537bf441 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 208eb7ac077..1703a518e48 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 53dd50c6068..f8185a28029 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"