Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp2235067ybg; Fri, 5 Jun 2020 08:49:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyh9Fg/vGKZh9cVfSW9X0hdjE3dJUYN5LnzQ3cNhY7dSnNRSSUXdnM8Y2+06lXJ3ejbrw2Y X-Received: by 2002:a17:906:76c4:: with SMTP id q4mr9888609ejn.371.1591372183538; Fri, 05 Jun 2020 08:49:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591372183; cv=none; d=google.com; s=arc-20160816; b=hxRVNxR350KVz6RayOZhHxj92hzVIAkv6vKbrHzKlytza6IpyWX1w8iBDahGV2jcJX htzGsRr2tw4WFJSQTc5dxCco+WtKd+X07ixHveI0TAX6G8Jgtl22tdEBSHj5W+WVRSGU 6XgalS4FJTqg4+DscTmaYLN4kNrStRKqnbak/nhaffs/I+5bq7SWx5GSUSVZhO8l1xoo Riej7v4ibkb7Nr1hHZsvoBk3LxXyCuBZbBFErdoAnfIYoSZcr65NXLvRamxXnKFBi1kf Amr1anDazLNYnnMkXhMDTwGI8aFbxjNlRgPQH2veb2lgRycbOJNsIlYrzAy1uTXXMP08 4dOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=d9xeqZrkxQM0vBgMkq7YMz3gisI1E50I8rLnmzeeZlU=; b=PSrjn3d5R/TAalrOoyf0XfRt6uY3m4PsNK7/8dxpNI0RSp1L0ofd3+hpWjupIBR9LZ 7STtW7TmFkAcv5IXKCljlAZTkSD6ZFVpFyyb3HzVVyB0Krr8mSCHsBvCdes6fZ0BQ6Ad KWfxS2WCYjR0i2cCdH5t9dK8I+0iyG+3sXXhRCtbJ026gWBnmrhUFMvwpjnF+rDc95Zt mzb/S8+vFe17hAPgjEp1UdPx3Xc3fqMO+jJ4e1mMEcdU4zEFrnlVCh6qc+c2WdZov7WR vDCGAoCV5JfWBiGCFvpVZPYfOJtoAQWkgNa///Yz9vWLaWRT3r7p0OzxeZrC91RgSUqn D2nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zO5eW9+u; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o23si3527523ejd.302.2020.06.05.08.49.12; Fri, 05 Jun 2020 08:49:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zO5eW9+u; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726802AbgFEPtF (ORCPT + 99 others); Fri, 5 Jun 2020 11:49:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:38994 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726729AbgFEPtF (ORCPT ); Fri, 5 Jun 2020 11:49:05 -0400 Received: from sol.localdomain (c-107-3-166-239.hsd1.ca.comcast.net [107.3.166.239]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 452742075B; Fri, 5 Jun 2020 15:49:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591372144; bh=fhSt8gBcDKl/O32yutyXIRsQjRoka5UOjtiH/O+HNYA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=zO5eW9+ujVmT1pbL8ggccexkpzKTaRApk39lxGxqG3pXPm6IPBHZ+kpNv+vYK5iXB 8UiPoCrjnL0rIYfSPY+Nh33lIane1O/Ab3grbL8as3a3E9AtvlPagloPWhQZ6V0BQo yVJ60rCRw++obLeqDRlOCVxbYWaNE9ScFcOG0ZMc= Date: Fri, 5 Jun 2020 08:49:02 -0700 From: Eric Biggers To: Zhangfei Gao Cc: Herbert Xu , Greg Kroah-Hartman , Jonathan Cameron , wangzhou1 , linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, kbuild-all@lists.01.org Subject: Re: [PATCH] crypto: hisilicon - fix strncpy warning with strlcpy Message-ID: <20200605154902.GA1373@sol.localdomain> References: <202006032110.BEbKqovX%lkp@intel.com> <1591241524-6452-1-git-send-email-zhangfei.gao@linaro.org> <20200604033918.GA2286@gondor.apana.org.au> <20200604061811.GA28759@gondor.apana.org.au> <20200604065009.GA29822@gondor.apana.org.au> <20200605121703.GA3792@gondor.apana.org.au> <47b747d2-3b27-4f39-85c9-204c2b8a92e1@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <47b747d2-3b27-4f39-85c9-204c2b8a92e1@linaro.org> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Fri, Jun 05, 2020 at 11:26:20PM +0800, Zhangfei Gao wrote: > > > On 2020/6/5 下午8:17, Herbert Xu wrote: > > On Fri, Jun 05, 2020 at 05:34:32PM +0800, Zhangfei Gao wrote: > > > Will add a check after the copy. > > > > > >         strlcpy(interface.name, pdev->driver->name, sizeof(interface.name)); > > >         if (strlen(pdev->driver->name) != strlen(interface.name)) > > >                 return -EINVAL; > > You don't need to do strlen. The function strlcpy returns the > > length of the source string. > > > > Better yet use strscpy which will even return an error for you. > > > > > Yes, good idea, we can use strscpy. > > +       int ret; > > -       strncpy(interface.name, pdev->driver->name, sizeof(interface.name)); > +       ret = strscpy(interface.name, pdev->driver->name, > sizeof(interface.name)); > +       if (ret < 0) > +               return ret; You might want to use -ENAMETOOLONG instead of the strscpy return value of -E2BIG.