From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202602 header.b=AVzW+F8z; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 98C025A0272 for ; Fri, 27 Mar 2026 05:34:43 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1774586072; bh=OPmR7+6Dq6qrPNa+3Tkd4Bdh7++tI8uybAok3M0yRzA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AVzW+F8zpDc9pRG03Tuur1keA4+uiK3skw/p8+14bxtwoH+194A6S2TpCxz6c+60m zZ3MAIh0IoxuBT9f/Yt8WQfsWBEnZen4LkfxXv6Bbkso1mhl7oMvkzzcGpYan4G+GM MER0uqfeyJ2QE+hmgxybcuARRWTHRyVzPzn++Rwx+wTZhe5HPYTAfSPcI4Tz6whEUO zJf5tWftBiJuo13W7dmqxTvYl5eNFBd12wE3HxbiqU6g+9ardWUTYGgpajHxSYOeU/ lkXbf7n7t8IVW/7J1stadMdUT9Jvp24YKdHG8sKoBCoiwEClaUtey4nFxArkXdZwWx qi+hlin1VjOPg== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4fhnqD659dz4wTC; Fri, 27 Mar 2026 15:34:32 +1100 (AEDT) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH 15/18] pif: Limit pif names to IFNAMSIZ (16) bytes Date: Fri, 27 Mar 2026 15:34:27 +1100 Message-ID: <20260327043430.1785787-16-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260327043430.1785787-1-david@gibson.dropbear.id.au> References: <20260327043430.1785787-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: HUYWZ6ATCPJLLVM56XXMTL5YRRKDEJYR X-Message-ID-Hash: HUYWZ6ATCPJLLVM56XXMTL5YRRKDEJYR X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: David Gibson X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: All current pif names are quite short, and we expect them to remain short when/if we allow arbitrary pifs. However, because of the structure of the current code we don't enforce any limit on the length. This will become more important with dynamic configuration updates, so start enforcing a length limit. Specifically we allow pif names to be up to IFNAMSIZ bytes, including the terminating \0. This is semi-arbitrary - there's no particular reason we have to use the same length limit as kernel netif names. However, when we do allow arbitrary pifs, we expect that we might support a similar number to the number of kernel interfaces. It might make sense to use names matching kernel interface names in that future. So, re-use IFNAMSIZ to avoid surprise. Signed-off-by: David Gibson --- pif.c | 2 +- pif.h | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pif.c b/pif.c index 1e807247..4e25e3fa 100644 --- a/pif.c +++ b/pif.c @@ -17,7 +17,7 @@ #include "inany.h" #include "epoll_ctl.h" -const char *pif_type_str[] = { +const char pif_type_str[][IFNAMSIZ] = { [PIF_NONE] = "", [PIF_HOST] = "HOST", [PIF_TAP] = "TAP", diff --git a/pif.h b/pif.h index 7bb58e5c..c467a941 100644 --- a/pif.h +++ b/pif.h @@ -35,7 +35,8 @@ enum pif_type { PIF_NUM_TYPES, }; -extern const char *pif_type_str[]; +/* Limit pif names to the same length as kernel interface names */ +extern const char pif_type_str[][IFNAMSIZ]; static inline const char *pif_type(enum pif_type pt) { @@ -43,6 +44,7 @@ static inline const char *pif_type(enum pif_type pt) return pif_type_str[pt]; else return "?"; + static_assert(sizeof("?") <= IFNAMSIZ); } static inline const char *pif_name(uint8_t pif) -- 2.53.0