Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp250394yba; Wed, 8 May 2019 19:57:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqwoAM/6aQu4jROZZKLbPTRIYMD9pg7MlURnkVMXRz+QJXMOfqXVlb6Vb4WZtLfPuNherEvZ X-Received: by 2002:aa7:8e0d:: with SMTP id c13mr1723054pfr.193.1557370654445; Wed, 08 May 2019 19:57:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557370654; cv=none; d=google.com; s=arc-20160816; b=TH+t1eZPDH5+20gjd6snfs0cdowuG1zlBqL4ci4ZkrbxD7GIvtcgBbtZSuXYhnlnlP 4XhOrsvK+jUCZizn9kGQEK6QUwFGvQrV3IXJqbNOIB51tB0aXtaniTFFV0cK10rhzpE9 lGTkhAo1/zQoCNAA4ahIWfx3KVLBgctY+7qjw8IK46NXVIDGNX4joJi81MYdzXlfkgA9 zQ4+cX8OUb//29wEsPmSvtkCSWijs/shP7QNCFJ32U6xjE0ASwVFa1CuOYfHNPskyYKi B7wbRgbMA1/ZBWaQ7SjxWkwi8v/sdR/TbBoBUjrYc8f4/uyZwa3aXoaA0bjs+5FgQSpt bRIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=Si2KOTfckft8jFqQjbj7a8ctTLTriInyUmF/NTDHRIc=; b=BQTtUtgStgteXfDdINpAvBczXMZ9PsO+c7B7AFNVeMNMLaRDnOkvh470URwhQQGwBX 5Ws4zbtLSXVdf3sznvUegJOA2TfoLU1eYP2C6zlYXFZOsdfoUGu/0KCPKpAh+wfWvKKL I39T4kzpdI2DvDBFuWNDT4y3H+oOZoTkZoMjNeufsPCzwEQ+qTnacVUu5EZwuQKWYMiN FRHjA+x6NwszURbcFGI9Pi/SP1r18TAeRJ90w4pUFs7K20kEls8Nq692KPdigFxmNcZg Xeo87lNiljlgosFq0DYmGJGk23MNuQHRzv3JSyRifMpPIbsMlfD29hu691g1QBkHQgAU DGyA== 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 cd12si1171026plb.92.2019.05.08.19.57.16; Wed, 08 May 2019 19:57:34 -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 S1726438AbfEIC4X (ORCPT + 99 others); Wed, 8 May 2019 22:56:23 -0400 Received: from mail1.windriver.com ([147.11.146.13]:62113 "EHLO mail1.windriver.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725922AbfEIC4X (ORCPT ); Wed, 8 May 2019 22:56:23 -0400 Received: from ALA-HCA.corp.ad.wrs.com ([147.11.189.40]) by mail1.windriver.com (8.15.2/8.15.1) with ESMTPS id x492u8Vk004135 (version=TLSv1 cipher=AES128-SHA bits=128 verify=FAIL); Wed, 8 May 2019 19:56:08 -0700 (PDT) Received: from [128.224.162.183] (128.224.162.183) by ALA-HCA.corp.ad.wrs.com (147.11.189.50) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 8 May 2019 19:56:07 -0700 Subject: Re: [PATCH] kdb: Fix bound check compiler warning To: Daniel Thompson CC: , , , References: <1557280359-202637-1-git-send-email-wenlin.kang@windriver.com> <20190508081640.tvtnazr4tf5jijh7@holly.lan> From: Wenlin Kang Message-ID: Date: Thu, 9 May 2019 10:56:03 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <20190508081640.tvtnazr4tf5jijh7@holly.lan> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Originating-IP: [128.224.162.183] Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 5/8/19 4:16 PM, Daniel Thompson wrote: > On Wed, May 08, 2019 at 09:52:39AM +0800, Wenlin Kang wrote: >> The strncpy() function may leave the destination string buffer >> unterminated, better use strlcpy() instead. >> >> This fixes the following warning with gcc 8.2: >> >> kernel/debug/kdb/kdb_io.c: In function 'kdb_getstr': >> kernel/debug/kdb/kdb_io.c:449:3: warning: 'strncpy' specified bound 256 equals destination size [-Wstringop-truncation] >> strncpy(kdb_prompt_str, prompt, CMD_BUFLEN); >> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >> >> Signed-off-by: Wenlin Kang >> --- >> kernel/debug/kdb/kdb_io.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c >> index 6a4b414..7fd4513 100644 >> --- a/kernel/debug/kdb/kdb_io.c >> +++ b/kernel/debug/kdb/kdb_io.c >> @@ -446,7 +446,7 @@ static char *kdb_read(char *buffer, size_t bufsize) >> char *kdb_getstr(char *buffer, size_t bufsize, const char *prompt) >> { >> if (prompt && kdb_prompt_str != prompt) >> - strncpy(kdb_prompt_str, prompt, CMD_BUFLEN); >> + strlcpy(kdb_prompt_str, prompt, CMD_BUFLEN); > Shouldn't that be strscpy? Hi Daniel I thought about strscpy, but I think strlcpy is better, because it only copy the real number of characters if src string less than that size. > > > Daniel. > >> kdb_printf(kdb_prompt_str); >> kdb_nextline = 1; /* Prompt and input resets line number */ >> return kdb_read(buffer, bufsize); >> -- >> 1.9.1 >> -- Thanks, Wenlin Kang