From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-170.mta1.migadu.com (out-170.mta1.migadu.com [95.215.58.170]) (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 5C14A3EF640 for ; Mon, 27 Jul 2026 10:29:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785148164; cv=none; b=JaBdBJonWKGIX+7N9MXuoObFRsmw6JZ7n/zAuGUvciwWnDicLX5dL5IUwjvT5uYUbjON3RiDUPILQecG4GlhfGQzwAkE/pOak6hOeJtCtC8f3s/bsL/NvDg3L3aige6infvS8IBlG2J1hIN8T70YPPtJzgdHQ7mpTq3UJiAO2BM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785148164; c=relaxed/simple; bh=AHEnZWlPYDaatGBVMiUfpmBDFa/uW+CNxGMF2+qVcX0=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=i3l0I6PIOLzuS8RnvlOWREXMhcSzxfZJLoedoM0FuISkhqbhhVYQojjVekC8yr50kFG3gVW2Rq2jOCxMtbwrEk+Hjtof3F3b+kfa/MjuT7fJDlmRfByAxlZQO9lZa9xx6MLHkDP5EZlpkOaNS7tUtq9LlWVV2/MNkcvzUFvTxgw= 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=i+3C/7E/; arc=none smtp.client-ip=95.215.58.170 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="i+3C/7E/" 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=1785148154; 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=P4QJwp1QO4pDD9YQvTdgnCc901AiYQ96b57Wi2E8LA0=; b=i+3C/7E/IA76fmlWtubXr/5y+tXik4Qy+u9TLhFN1koh4Rk/W6TTXh8zcwkeExe2ouBBW5 e3KOn0N+G0wjVDsfUUx+AjIczefTUIRgy6Snupa+jes74YHhXkqizJ1ZjZE1Pu1/WsGqNH Pm6X07SUdgMFHCT3EUKdexoiByRS2/o= From: Thorsten Blum To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Ard Biesheuvel , Andrew Morton , "Mike Rapoport (Microsoft)" , Thomas Zimmermann , Arnd Bergmann , Harshit Mogalapalli Cc: Thorsten Blum , Ingo Molnar , linux-kernel@vger.kernel.org Subject: [PATCH RESEND v2] x86/setup: Replace strlcat() with snprintf() in setup_arch() Date: Mon, 27 Jul 2026 12:28:45 +0200 Message-ID: <20260727102845.412529-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 X-Developer-Signature: v=1; a=openpgp-sha256; l=1814; i=thorsten.blum@linux.dev; h=from:subject; bh=AHEnZWlPYDaatGBVMiUfpmBDFa/uW+CNxGMF2+qVcX0=; b=owGbwMvMwCUWt7pQ4caZUj3G02pJDFnpRnfX1k87fkbRroZniWGFd13lLK6TG019G6e5leQYP Joj/Neoo5SFQYyLQVZMkeXBrB8zfEtrKjeZROyEmcPKBDKEgYtTACZiVsLwT6/j1YIvNw0aWD9u nvO1LrK35p5Q1wTDT6wZ6dZH385b0M/IsE8j5J7aYcH937zknHnfJjSte2F4J3Ezbxubfaf/+6V ajAA= X-Developer-Key: i=thorsten.blum@linux.dev; a=openpgp; fpr=1D60735E8AEF3BE473B69D84733678FD8DFEEAD4 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT In preparation to remove strlcat() from the kernel [1], replace two strlcat() calls with snprintf() in setup_arch(). Also drop the explicit size argument to strscpy() to further simplify the code since strscpy() can determine the size automatically when the destination buffer has a fixed length. Link: https://github.com/KSPP/linux/issues/370 [1] Signed-off-by: Thorsten Blum --- Changes in v2: - Use a Link: tag as suggested by Andy - v1: https://lore.kernel.org/r/20260604131752.1327556-3-thorsten.blum@linux.dev/ --- arch/x86/kernel/setup.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c index 46882ce79c3a..b11b0ce31a27 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -915,16 +916,18 @@ void __init setup_arch(char **cmdline_p) strscpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE); #else if (builtin_cmdline[0]) { + size_t len = strnlen(builtin_cmdline, COMMAND_LINE_SIZE); + /* append boot loader cmdline to builtin */ - strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE); - strlcat(builtin_cmdline, boot_command_line, COMMAND_LINE_SIZE); + snprintf(builtin_cmdline + len, COMMAND_LINE_SIZE - len, " %s", + boot_command_line); strscpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE); } #endif builtin_cmdline_added = true; #endif - strscpy(command_line, boot_command_line, COMMAND_LINE_SIZE); + strscpy(command_line, boot_command_line); *cmdline_p = command_line; /*