Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4745079yba; Sun, 12 May 2019 21:34:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqwnYQn3pz7B/EKwQ1pGJl3ucNW13EsakDPq6aW66YZT0T4kijOjhH9IwhqFNhxsxavB1q5P X-Received: by 2002:a17:902:5ac8:: with SMTP id g8mr28722769plm.154.1557722080162; Sun, 12 May 2019 21:34:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557722080; cv=none; d=google.com; s=arc-20160816; b=xogeok6SviSwYVdANGQSAU3ZD8dLn7NSs6OD/VPAtagPhRg2PaaseAZHknoIDPgQaS qtvZz0Z9Ugf6GBjGH4mezVEU95e3HXM8fWDy8a0TUIzMKwtSxnKwlhjyA6Pms5kkbfNk TrL3Av94WqD17LEphUsylr9bbxTpqierxbmbDX+O+Oeekn06wFsWkpbdRDQ3ZXQIlDa5 WsQwGhrvzFk6BAjkb4iB6QnIhcjD9i8pJCNQfvYHRzyr5VTqPA+6Oos54kSrzsraogKg ok2mxKPC5XrnBkoZq+/54HWw6hLxWKgHwJQrO/w622+EgRSDDB1519ECI1grIJcxmaie c1ug== 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=O9JzjCqVyPTyHcFgbFrSswWze5hRTqNUC69es5DVy1E=; b=Pp1pUO0fpcvWYzbfDQo2rdDwCXp5IOY4H9YHxOBt1LTdB51EkBM8AHQI6CBXzg1+NU /8eMTq3hTCcs3Mbv1x026teuL4SzZM8Y5huD2l1PEYLE34Wre6BLIPRJvFtJRbzeBB1C Yiv0YD2bw5TaHYyCp3S1gu1yZjIW8UQmYloz0ImV4VibVlpD5dtYGJp3I7QymAi/0Uuz tiey4huL5mt5HIbNkeT4Vh9kmfXnQGFB4FPtd3IYDeryb1y2S1d9/aoInsoEkAz+B9Fo lakVuRymtTlgcJbK1ivOdz3d0bTN/1TLGtGSorAp93N1SXdOtpwh4NZiMcQkmnSuOZGE hyCQ== 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 e64si2241275pfe.178.2019.05.12.21.34.23; Sun, 12 May 2019 21:34:40 -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 S1727499AbfEMDkG (ORCPT + 99 others); Sun, 12 May 2019 23:40:06 -0400 Received: from mail.windriver.com ([147.11.1.11]:41009 "EHLO mail.windriver.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727202AbfEMDkG (ORCPT ); Sun, 12 May 2019 23:40:06 -0400 Received: from ALA-HCA.corp.ad.wrs.com ([147.11.189.40]) by mail.windriver.com (8.15.2/8.15.1) with ESMTPS id x4D3doEo017640 (version=TLSv1 cipher=AES128-SHA bits=128 verify=FAIL); Sun, 12 May 2019 20:39:51 -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; Sun, 12 May 2019 20:39:50 -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> <20190512090003.de52davu55rrg7kn@wychelm.lan> From: Wenlin Kang Message-ID: <0c5121f7-645c-3651-cccc-2ae836d415b6@windriver.com> Date: Mon, 13 May 2019 11:39:47 +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: <20190512090003.de52davu55rrg7kn@wychelm.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/12/19 5:00 PM, Daniel Thompson wrote: > On Thu, May 09, 2019 at 10:56:03AM +0800, Wenlin Kang wrote: >> 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. > Sorry, I'm confused by this. What behavior does strscpy() have that you > consider undesirable in this case? Hi Daniel I checked strscpy() again, and think either is fine to me, if you think strscpy() is better, I can change it to this, and send v2, thanks for your review. > > Daniel. > -- Thanks, Wenlin Kang