Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp2575375ybh; Mon, 5 Aug 2019 03:18:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqxAExE4J4pzsVuASvZeHbskRJbs3MigP3ey/mpbRULwzmHjEICfEn5fqhu5pGpP9Fi2/HDC X-Received: by 2002:a65:5144:: with SMTP id g4mr83444222pgq.202.1565000332737; Mon, 05 Aug 2019 03:18:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565000332; cv=none; d=google.com; s=arc-20160816; b=Z/U645fLGFxgIa52AQo07fO54cTNAo12Vr5lLNnQv7ntmjZX/ZD1kk7X3Qb7kBxP1I i+U7dVP013zZt4Xj6hdnKk0sWHPc5XnE16Z1NGNNIX/7WPFbRKALxS8nIx+oOkBUFsjh miXRoC/wNZ58QrBVk55AypgMwPObcPWJi167h4GPxpHUGBLQw4wTes2e+zIzSuMO1yaz CMxQKgGObBVdY0JmuGPYnUFrlahF+cG7x2D3NoQeYuHgM0kcA2Dth7icAauOE6c7dGNw GcQv8UihfYar2YyoLxDe7UAuSyx8MUnJrEZFCBom1ziR/fWR2Yg6Gix7ltzDKNAZ8U2Y xZEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:message-id:date:subject:cc:from; bh=+HtoRO9CAcJMTmo5v89UFaToWNUfme3JcVzfwZ3XcpE=; b=RPysi6R079x5SZRvzivFAbHtwZ9tTXsiCaPOl9N6W/fKd05H3i5JhgZoCwtW8oX/9W lHQ06BPX+zFqx8otsMZzVlAeqEwUcCAn53FfVqzC50Iin4Bzkktk+eOY1mMYSkaaxOcO kQS3hdgHXx/Cf3nprO+QIavPIrEUmIJKvXRzvYn6jXfTa3xqMFcn+C9LwiWvP8XzhII4 V37d0y12LxGatYX0hvcmn35NEcOlIjnBDpYIH+fbPW2krK/OekFs9llsyG1qoJBz+Sij cBCj3cxLeFjE1RomyWpvp6S+QzhSNe96WCs52ZzH2J1vedEZ3oCgGmbUDbx/bx98C5cL HNSA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t11si39118081pgu.16.2019.08.05.03.18.37; Mon, 05 Aug 2019 03:18:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728372AbfHEKRU (ORCPT + 99 others); Mon, 5 Aug 2019 06:17:20 -0400 Received: from smtp180.sjtu.edu.cn ([202.120.2.180]:52172 "EHLO smtp180.sjtu.edu.cn" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727989AbfHEKRT (ORCPT ); Mon, 5 Aug 2019 06:17:19 -0400 Received: from proxy01.sjtu.edu.cn (unknown [202.112.26.54]) by smtp180.sjtu.edu.cn (Postfix) with ESMTPS id 0F71210089E14; Mon, 5 Aug 2019 18:17:17 +0800 (CST) Received: from localhost (localhost [127.0.0.1]) by proxy01.sjtu.edu.cn (Postfix) with ESMTP id F0F422042423F; Mon, 5 Aug 2019 18:17:16 +0800 (CST) X-Virus-Scanned: amavisd-new at proxy01.sjtu.edu.cn Received: from proxy01.sjtu.edu.cn ([127.0.0.1]) by localhost (proxy01.sjtu.edu.cn [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id hJCk14iFE37W; Mon, 5 Aug 2019 18:17:16 +0800 (CST) Received: from xywang-pc.ipads-lab.se.sjtu.edu.cn (unknown [202.120.40.82]) (Authenticated sender: xywang.sjtu@sjtu.edu.cn) by proxy01.sjtu.edu.cn (Postfix) with ESMTPA id CB5602042423E; Mon, 5 Aug 2019 18:17:16 +0800 (CST) From: Wang Xiayang Cc: lftan@altera.com, rppt@linux.vnet.ibm.com, nios2-dev@lists.rocketboards.org, linux-kernel@vger.kernel.org, Wang Xiayang Subject: [PATCH] nios2: force the string buffer NULL-terminated Date: Mon, 5 Aug 2019 18:17:12 +0800 Message-Id: <20190805101712.22580-1-xywang.sjtu@sjtu.edu.cn> X-Mailer: git-send-email 2.11.0 To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org strncpy() does not ensure NULL-termination when the input string size equals to the destination buffer size COMMAND_LINE_SIZE. Besides, grep under arch/ with 'boot_command_line' shows no other arch-specific code uses strncpy() when copying boot_command_line. Use strlcpy() instead. This issue is identified by a Coccinelle script. Signed-off-by: Wang Xiayang --- arch/nios2/kernel/setup.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/nios2/kernel/setup.c b/arch/nios2/kernel/setup.c index 6bbd4ae2beb0..4cf35b09c0ec 100644 --- a/arch/nios2/kernel/setup.c +++ b/arch/nios2/kernel/setup.c @@ -123,7 +123,7 @@ asmlinkage void __init nios2_boot_init(unsigned r4, unsigned r5, unsigned r6, dtb_passed = r6; if (r7) - strncpy(cmdline_passed, (char *)r7, COMMAND_LINE_SIZE); + strlcpy(cmdline_passed, (char *)r7, COMMAND_LINE_SIZE); } #endif @@ -131,10 +131,10 @@ asmlinkage void __init nios2_boot_init(unsigned r4, unsigned r5, unsigned r6, #ifndef CONFIG_CMDLINE_FORCE if (cmdline_passed[0]) - strncpy(boot_command_line, cmdline_passed, COMMAND_LINE_SIZE); + strlcpy(boot_command_line, cmdline_passed, COMMAND_LINE_SIZE); #ifdef CONFIG_NIOS2_CMDLINE_IGNORE_DTB else - strncpy(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE); + strlcpy(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE); #endif #endif -- 2.11.0