Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4889028yba; Mon, 13 May 2019 01:17:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqxLeta2RnqA2jRSOHzD/VVl0qs9u59g9MFP5St+MBSt/fbdDyiIzmKDGG8Qq2k0pqYQc+2t X-Received: by 2002:aa7:810e:: with SMTP id b14mr32018000pfi.112.1557735475273; Mon, 13 May 2019 01:17:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557735475; cv=none; d=google.com; s=arc-20160816; b=lzFqfalhoQLg96NC7BnGWOTHeeuqH2Y2Xzg2DAsE0xyss/9BnGCMpIM/NREwIBoVeV UAnkougjMqrGOd35MRR0I+Z60p2c5WwAdnPthbtbi+HE8HdNyVpdcV+tf5UInRcCt7qK kE9hj+xmwHYGdzoCyttVunIuNpYDUXEJimuh8Ash8JP5lGOrqXYwnzNzbpNpq6mdj6zU cN3lXZaCQg2Qt9kOJENaH8X28G8tBBtRAPizQmFfPaw80FemG1SKe/CEhN/ZwNF6rvUA E5nL9XM2oL5sAz8Zmtw0qWH5ZqY4fIIi1Yq9wCEcMK6z+zitB3FRKpPRjPx8DGAKjP+S lJHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=GbstJVyW1AtQn0uCOokyeICMnnihu2g5VNt0MV0fVRw=; b=ErnhMrr7c+VhbXz+A2fg6D0tNq9M8QXbGeKYbrlDvvhq6YuQMFLeVgmrpPB1hItr0H LyeOVU3yUeZWTRMeka+hs1q8YrJlu5/+r+YGb6dnNo1qwNH/riBRBpTjtzRuQ8dujNeU b+wdhL4BS8hh5ymEsSl7HoCS0H8Cj85miNPs64LK4sHRZJVHolyH302Yb/IMzbUHDdPo t1wXywFJJUiiJaWPbTgVXFEIydHt1IlxbLpKeTRxIrB5wE05HzRzQNW4pEC3bj5PQyXA 1bAPE4Ipp5xc1TBGl8oIAZG5nhtmBaWN2X/LfGWfuleLkViyLwufgPxow75qyD0aoMmT O84w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NsdcE677; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m189si4631881pgm.13.2019.05.13.01.17.37; Mon, 13 May 2019 01:17:55 -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; dkim=pass header.i=@linaro.org header.s=google header.b=NsdcE677; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728109AbfEMHos (ORCPT + 99 others); Mon, 13 May 2019 03:44:48 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:45108 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728101AbfEMHor (ORCPT ); Mon, 13 May 2019 03:44:47 -0400 Received: by mail-wr1-f67.google.com with SMTP id b18so4023844wrq.12 for ; Mon, 13 May 2019 00:44:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=GbstJVyW1AtQn0uCOokyeICMnnihu2g5VNt0MV0fVRw=; b=NsdcE677iiLa6/IG0QmYfUg1mJqtJgcJIBPmrYoGXf7HmCEJJIm0yONFrNG9JD73jM 7+dFIEL9HKpTCmVMlx7GoRq7P2BSklJhQ6v2MN+kVtpjc5sK+sBmnoiI61faAD3LOFpK xm3JpbHXFaMd1B5lP9KyEtk7HO2ZghB061Oh7U3TIy7btqR295rwud6g3jAxJxnhwov1 nIqRnSqQF6YtMRZ1lUUm0Y6CJd1V80mJW1oeBc8KeNoUUQqGrEfO3dgnvir5pa3zrFzW Spe9k2wBvyQhswd3H8VwU8YEDGW8bBtB6dHfeErWVrRKBnc4LF5a9XyXkSly9b13zOmq jdvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=GbstJVyW1AtQn0uCOokyeICMnnihu2g5VNt0MV0fVRw=; b=HjYTQtuF4GLNC4jfNhoIUEZ4M3gEyblFrGpKmg7Xv6xqMe40jz2Nhp80PpO0xb4RHj UDTuJMDLJNg03SaFUbuyyx159gQvjMPt8PDsV1kGkXI/c96GTmRmxYK3CmYxhs4ZFe4v 364hVKujjGxDyfY9LSxSYUtqYC33KMNUHlG4X6jX2y4XeujLKgRCJ7OEbEZs/9ffi7wL vzFqeQjmwoapdijqKUlJfaEOi5mGfyMt+4IpVqZeSZ7fXEGEVVuRY5FFOQ+HtBSkUBsL pa7LBPhDnHU41HjXOu7H6lFT1M+CMPbcdQveWzjrbCf0zosvlrym0/bhHKK+17M1Ymth L9vw== X-Gm-Message-State: APjAAAU7yYkk3fpUQEhc4VWQiDR5ncgx4WDo9kj5jqX2MgD/Hwb3q5XN 9F+iaoiT/2ujdxYHUqvLkV7Eog== X-Received: by 2002:adf:f841:: with SMTP id d1mr9758107wrq.62.1557733486527; Mon, 13 May 2019 00:44:46 -0700 (PDT) Received: from holly.lan (cpc141214-aztw34-2-0-cust773.18-1.cable.virginm.net. [86.9.19.6]) by smtp.gmail.com with ESMTPSA id g2sm3521885wru.37.2019.05.13.00.44.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 13 May 2019 00:44:45 -0700 (PDT) Date: Mon, 13 May 2019 08:44:44 +0100 From: Daniel Thompson To: Wenlin Kang Cc: jason.wessel@windriver.com, prarit@redhat.com, kgdb-bugreport@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: Re: [PATCH] kdb: Fix bound check compiler warning Message-ID: <20190513074444.eftse5jimrl4xtc7@holly.lan> References: <1557280359-202637-1-git-send-email-wenlin.kang@windriver.com> <20190508081640.tvtnazr4tf5jijh7@holly.lan> <20190512090003.de52davu55rrg7kn@wychelm.lan> <0c5121f7-645c-3651-cccc-2ae836d415b6@windriver.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0c5121f7-645c-3651-cccc-2ae836d415b6@windriver.com> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 13, 2019 at 11:39:47AM +0800, Wenlin Kang wrote: > 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. I think strscpy() is better. Daniel. > > > > > > Daniel. > > > > -- > Thanks, > Wenlin Kang >