Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp3861603imm; Mon, 25 Jun 2018 05:58:19 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJUGXg5wNiDlVahngAOg1Um/E8+NRtmEeeOWDfscsuCTWsmoeF0hIOfOD+xCTDMOmtHk/4m X-Received: by 2002:a17:902:262:: with SMTP id 89-v6mr12437890plc.252.1529931499620; Mon, 25 Jun 2018 05:58:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529931499; cv=none; d=google.com; s=arc-20160816; b=FM1je1N5yFhUsgczPKEwC8+xF5B7crH1kPCqZNHZXmPMg1zXP66DgboTXO9lMNOJU3 9bKcXYoVXSxwBOa+2+M5moV6GxJRrHxIvTOcxw4YLTYuoIcYVtiisHQiEwAxqNALtb0I kiWcTNnWYBVucCQsof/p6e4igdDtGCBd8qsDNbHsdR9/H+UKAT4WsQquJgQCClnu3R7F Qcd0ftnwpnpjun6vxvsa//0oRDdQYgxfSC1nQiCx7v4GyRyQbBnR8Z8AorTa1SeVhfQu vQjxmI/YJj9joAMNhBojAvHKH+ylzSLDoEE1gryO3sENrpoIW89Gzg9DIeSQM6OOZSgV Uxmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=bt3iRk/Tgz7TApnsjo5UCfnJ5cRKO0vEcmjXqeVak4U=; b=WXsIvI3uG4ysQcwHLMkBseRrDcuS1LZPcpib3hASunfLdK8LsMoa/WTki55dV8mnWI HTd85DK4jd229B2C0uq9eGeA0E1ddP1ZWT7GG7//Qu0T/QFuM9iB37IbPaY9ZNi7LXph O1Qoqm3yICTx/+Axbsxe8twhNWGDlxof0o2rHKCwvcMdYd2wFLdbUrrZW14ev22ZKJU8 TgSGu9npdIvaYh0l66b7R1jnz7YLoNHc/QezastedeKo6tyoKsmmWIE8zmy0b7bPo+vE vo6Eh37tEYKELQ+LB8iIg6P5QiLEXq8ApazGGSNgvIVS+DrJcRnVomd6E+Xeq1HIrOUl 701g== 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 q124-v6si1524135pfc.93.2018.06.25.05.58.05; Mon, 25 Jun 2018 05:58:19 -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 S933522AbeFYM5P (ORCPT + 99 others); Mon, 25 Jun 2018 08:57:15 -0400 Received: from pegase1.c-s.fr ([93.17.236.30]:20876 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755408AbeFYM5O (ORCPT ); Mon, 25 Jun 2018 08:57:14 -0400 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 41Dq2B05kkz9ttmv; Mon, 25 Jun 2018 14:57:06 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id KUSawa_jheTs; Mon, 25 Jun 2018 14:57:05 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 41Dq296kkNz9ttmL; Mon, 25 Jun 2018 14:57:05 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 6BD7D8B7C2; Mon, 25 Jun 2018 14:57:13 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id 6let07Prlgac; Mon, 25 Jun 2018 14:57:13 +0200 (CEST) Received: from PO15451 (po15451.idsi0.si.c-s.fr [172.25.231.35]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 3CD788B7A0; Mon, 25 Jun 2018 14:57:13 +0200 (CEST) Subject: Re: [PATCH v2 2/2] kobject: Fix -Wstringop-truncation warning To: Stafford Horne , LKML Cc: Greg KH , arnd@arndb.de, Eric Biggers , linux-crypto@vger.kernel.org References: <20180625124538.21051-1-shorne@gmail.com> <20180625124538.21051-3-shorne@gmail.com> From: Christophe LEROY Message-ID: Date: Mon, 25 Jun 2018 14:57:13 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <20180625124538.21051-3-shorne@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: fr Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Le 25/06/2018 à 14:45, Stafford Horne a écrit : > 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 not really an issue since the buffer we are writing to is > pre-zero'd and we have already allocated the buffer based on the > calculated strlen size and accounted for the terminating '\0'. > Just use memcpy() instead. If we are already sure the destination is big enough, why not just do a strcpy() and drop the 'cur = strlen()' ? Christophe > > Cc: Greg Kroah-Hartman > Cc: Arnd Bergmann > Cc: Eric Biggers > 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..e876957743c8 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); > + memcpy(path + length, kobject_name(parent), cur); > *(path + --length) = '/'; > } > >