From nobody Mon Dec 1 22:35:43 2025 Received: from out-181.mta0.migadu.com (out-181.mta0.migadu.com [91.218.175.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5803933FE03 for ; Wed, 26 Nov 2025 22:08:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764194929; cv=none; b=M0XkwMyRtrypGDD6isMBEqv6oghj/5t143Obx2ApgYhNN3L5KhKw/rCydBW9uQ+EXEW60Q24Rnk+yoqncOJV4hZGET49ZYR48aQQngrSvkqOBu3Zd4ITgkfNZUkH2nGmEznEBmJkOSRI36EOmvXZPyQ36YlNMpC5x571GT3TgN4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764194929; c=relaxed/simple; bh=0IfWLNUcsz19oellpUkIA+gy1/IqfDvXxC4vSe6yuFU=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=jAIaAm6X6EZNvccy8H8nAfku49Iag4g1rZL5hMHQ3xZLn0HE0L+thLluhEZkRxjoWSUayy5v5FLEZPHxZ+DQXYqjqaHHL4ImDiYHJacmVU4fqKGPh60iB3a5Wmz7Hq4tkyWD5lbyenNM8e/MEcLWx683crV7yWzdowXn0B+Nd2c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=stGyVsFn; arc=none smtp.client-ip=91.218.175.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="stGyVsFn" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1764194915; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=bwQ1V5HM+PRmRRY2kwdC1ABNayKu18UgYBDDHCXbeY0=; b=stGyVsFnqTrTlNzlpWnYjzruCr8UyRINPklF4UilrT/RKG/SGPp7CBDRHjeMPopXsvtXu2 /FBcCYuvy6cQyUh3kxU0CfylaxMORzeLUOAmJLteWUVtudHFyvTQNX7aSPD4axqAbP6yHT CEU4FU1bFQzGTLk4OAuj8uhFUrNrNyc= From: Thorsten Blum To: david laight , "David S. Miller" , David Ahern , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: Thorsten Blum , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v2] net: ipconfig: Replace strncpy with strscpy in ic_proto_name Date: Wed, 26 Nov 2025 23:08:05 +0100 Message-ID: <20251126220804.102160-2-thorsten.blum@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" strncpy() is deprecated [1] for NUL-terminated destination buffers because it does not guarantee NUL termination. Replace it with strscpy() to ensure the destination buffer is always NUL-terminated and to avoid any additional NUL padding. Although the identifier buffer has 252 usable bytes, strncpy() copied only up to 251 bytes to the zero-initialized buffer, relying on the last byte to act as an implicit NUL terminator. Switching to strscpy() avoids this implicit behavior and does not use magic numbers. The source string is also NUL-terminated and satisfies the __must_be_cstr() requirement of strscpy(). Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncp= y-on-nul-terminated-strings [1] Signed-off-by: Thorsten Blum --- Changes in v2: - Use strscpy() to avoid unnecessary padding (David) - Update patch title and description accordingly - Link to v1: https://lore.kernel.org/lkml/20251126111358.64846-1-thorsten.= blum@linux.dev/ --- net/ipv4/ipconfig.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c index 22a7889876c1..019408d3ca2c 100644 --- a/net/ipv4/ipconfig.c +++ b/net/ipv4/ipconfig.c @@ -1690,7 +1690,8 @@ static int __init ic_proto_name(char *name) *v =3D 0; if (kstrtou8(client_id, 0, dhcp_client_identifier)) pr_debug("DHCP: Invalid client identifier type\n"); - strncpy(dhcp_client_identifier + 1, v + 1, 251); + strscpy(dhcp_client_identifier + 1, v + 1, + sizeof(dhcp_client_identifier) - 1); *v =3D ','; } return 1; --=20 Thorsten Blum GPG: 1D60 735E 8AEF 3BE4 73B6 9D84 7336 78FD 8DFE EAD4