Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp1520244imm; Fri, 22 Jun 2018 19:32:53 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKmJeiqTpxarf/svUHynLI0eo19OkA6+T0azdyY2NNWaAhVRv2QL7ZND6/vM9r475C4xB3Q X-Received: by 2002:a17:902:59c5:: with SMTP id d5-v6mr3922026plj.253.1529721173464; Fri, 22 Jun 2018 19:32:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529721173; cv=none; d=google.com; s=arc-20160816; b=1DMD9tUvJAJ7TPhq4m0m+dAnm3K0j4ayxIMXNJ6DCg9UlDhFGkpyREbnAfsD4NBpkr w2tP0oNDnxvTlO2wUncTn7AsUsaYbzHQrI1vrgtDY6PoCB9zq9Ihv+6S9mC6YapX0377 MH/WQa2Ni2tdIGIX5K2BbrerOkQh5nONPuXM4wj/vrX3A8atpjH2fMGU0y5RZ41/3Su0 Xo0UITKcTKJzZKAto09RQEZtT7koXEUytE9srgTcNsOvI4gbRhVHGqBkGNPbbEfOkP2O bfm712vI1IQN+k22cu6bUQxeOwhJP753iBjElRzNms99am8PXVlgXKF93Quc1ECVOmbd JnBg== 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-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=A8qh48rlzzXackprY+OeOCMFWuvV+fDMOFQ9qifcOK4=; b=meZnKSvANNiM2d6k0ikcDYzxng7zgz7URC7LunvRWL0xYW/hs36vhGsdQZv/Nefctg b5l3KEL5UvESjDu5zNnC4zDRxKV57JzfvE/8e13nIrK5OGbpAs1icDrHa9CmLFxG89Rm NcZ0oZFLbC1uxuFzy30I9w+D0BYuvJGEAk7FtpKN3Bu9kuFFDHbooWymNDOz/nG84Mtv ZJaGR8D4zlTiTwdvAHWh1bmDbtKo7S+jmZicIFbAZWxr87wfiGA34MQ3TrzXc3gYllI8 5DMctw9zlgZuAvuROGQJbwSX+cDsRbKxJHbdz9omexLkUrpFEajBS7HlkCD76jFhbIOK kQsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=UbHxbHGt; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a73-v6si9027352pfl.349.2018.06.22.19.32.36; Fri, 22 Jun 2018 19:32:53 -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=@gmail.com header.s=20161025 header.b=UbHxbHGt; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964774AbeFWCby (ORCPT + 99 others); Fri, 22 Jun 2018 22:31:54 -0400 Received: from mail-pl0-f66.google.com ([209.85.160.66]:41063 "EHLO mail-pl0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934590AbeFWCbw (ORCPT ); Fri, 22 Jun 2018 22:31:52 -0400 Received: by mail-pl0-f66.google.com with SMTP id w8-v6so4281654ply.8; Fri, 22 Jun 2018 19:31:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=A8qh48rlzzXackprY+OeOCMFWuvV+fDMOFQ9qifcOK4=; b=UbHxbHGtljLs2ANisIhAS3/BZ36iIJBffZncq9uT901kuA4hKTBUWk4i0mbb9aSRql S8XG2mIRMN64ptQiwrStNBiwNEMamaRIkjibsPv9zvK1c4Deu7YwVaXTgSrdM5hwoDDZ wBNY+q5pfh9kh/EMSz6aR6azFq9X55VGMMhOZk2ehyzyITg7XqHrpc44bdXityxCcJif l+nkOsYjV8Y+ii8LhOg8eImq8JkBH6m6IZEdkShgyNDDRuuWMwFLdICcfmzRTjECCuWB YEo3Dj/H6m5v1ny1hRv2A7EvU5o+NjjVDbwBJnlGjXPW0O4Z3HGIVbtE4OTaTx0vMXNt Y+5w== 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:content-transfer-encoding :in-reply-to:user-agent; bh=A8qh48rlzzXackprY+OeOCMFWuvV+fDMOFQ9qifcOK4=; b=HEu+MORDeeRwhFpEVMmOoJBPPJ3oQY6RfXsCvowMif9sA7ltZut3OSfI3A58jvwQSv GRphQ2s93TL/bvUggR8qVNQ7W2TvaSpjqjmwWrvqD1rXB0BYJTv68NJEhg/Qqzh1mB4p JOoR36xEbuh9Ayt+G5qH6sVpxswpMF45r8izStdK+PaO2Yaj5Q+yLnkUJ2m7hUZkIVwI k89UbEufRVVuOD4naOSK9yihOsAf4LGKAm0j9cxny9mTXc/e0ffVP9Ag9nfT1GigOX96 TcQg+8Knpn2CMVSQW/3/z9ESQZII+GeyIm4uzB41KaGBPLA+RS8J4FZ3SZYglf4PxeoY dinA== X-Gm-Message-State: APt69E2U4GQzdlV8njtrqh8vwjNRUtOWeVh6zwLmttukGpmQokLefrJf hJAYAom7uGKZXrVMWbEDOKI= X-Received: by 2002:a17:902:b60c:: with SMTP id b12-v6mr3943350pls.44.1529721111970; Fri, 22 Jun 2018 19:31:51 -0700 (PDT) Received: from sol.localdomain (c-67-185-97-198.hsd1.wa.comcast.net. [67.185.97.198]) by smtp.gmail.com with ESMTPSA id q9-v6sm10851389pgv.84.2018.06.22.19.31.51 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 22 Jun 2018 19:31:51 -0700 (PDT) Date: Fri, 22 Jun 2018 19:31:49 -0700 From: Eric Biggers To: Stafford Horne Cc: LKML , Greg KH , arnd@arndb.de, linux-crypto@vger.kernel.org Subject: Re: [RFC PATCH 2/2] kobject: Fix -Wstringop-truncation warning Message-ID: <20180623023149.GA880@sol.localdomain> References: <20180623020753.27266-1-shorne@gmail.com> <20180623020753.27266-3-shorne@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20180623020753.27266-3-shorne@gmail.com> User-Agent: Mutt/1.10.0 (2018-05-17) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Jun 23, 2018 at 11:07:53AM +0900, Stafford Horne wrote: > When compiling with GCC 9.0.0 I am seeing the following warning: > > In function ‘fill_kobj_path’, > inlined from ‘kobject_get_path’ at lib/kobject.c:155:2: > lib/kobject.c:128:3: warning: ‘strncpy’ output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation] > strncpy(path + length, kobject_name(parent), cur); > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > lib/kobject.c: In function ‘kobject_get_path’: > lib/kobject.c:125:13: note: length computed here > int cur = strlen(kobject_name(parent)); > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > This is pointing out a bug that the strncpy limit is the source string not the > destination buffer remaining length. Fix it. > > Cc: Greg Kroah-Hartman > Cc: Arnd Bergmann > Signed-off-by: Stafford Horne > --- > lib/kobject.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/lib/kobject.c b/lib/kobject.c > index 18989b5b3b56..15338e5a96f2 100644 > --- a/lib/kobject.c > +++ b/lib/kobject.c > @@ -125,7 +125,7 @@ static void fill_kobj_path(struct kobject *kobj, char *path, int length) > int cur = strlen(kobject_name(parent)); > /* back up enough to print this name with '/' */ > length -= cur; > - strncpy(path + length, kobject_name(parent), cur); > + strncpy(path + length, kobject_name(parent), length); > *(path + --length) = '/'; > } It should be replaced with memcpy(), AFAICS; it wouldn't change the behavior but it would quiet the gcc warning. Your proposed "fix" is heavily broken: notice that the code is building a string backwards (end to beginning). - Eric