Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp1530115imm; Fri, 22 Jun 2018 19:51:10 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKpfl4fCOB/GXsffbBYSupGHgKG9z6IiFkr0QlR/TJvuwkuH4cEcP1IbTnsUv5MSd1cvAF2 X-Received: by 2002:a62:f948:: with SMTP id g8-v6mr4113764pfm.107.1529722270063; Fri, 22 Jun 2018 19:51:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529722270; cv=none; d=google.com; s=arc-20160816; b=Yc2GJoCKEzto/QL0KSPggU6gXnwRBsw9KLy/6HSph9kxPnpd7skubmlY68AhS3pw7D Uxp+ywzr4jMXmQyjHvHaoeIJiHlmtryMraTKG/OSiJTWdsR7sSQuZOqFN1zWdezciw9a Y+Ql30JNykOqClCCSjc8sUoVde0+56rB8TSd4eJT2NVn9vX7QI9rBFUMUHpfSIyWrKiB E97vo1sd+o/3fgbd7tiwOo1FEGaE+oPgm+nlK6xcrK0jWBbFx6gUjHklc4TyNcaxocZH Hcsy4DX+ivdr2DNh0ymOr/Sgm1Z+40KQEWW0iHRB0l8g6KUIKBitNdMtFSoboAbgIQHu njdg== 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=Ivu9PS4UdgUE05m+Iz9kv7lUvuj7BkhGemCtehaD73Y=; b=Uf0HTajG1hdev9DCvGCcQYlX/n9MGhWJSQvu1fjOM/puAS11VQ9wn4bPoGY2MuH9mx UdoZ/pMTiIlztM5kY1hxPP4ibEksIZ8A0Mnluk7gsNG6Aifu9KrAoRsHIRYYEvWOSgXH sYQE+Q14392EGUC8+CWSYeVfR3yWlrK4wJa4QqCzKRE59un1KUJOtjiiEHUZPwWqGZc+ tZZg8hMu49Ml1rsenlZdgA2T7BbFeiTN2i8TfWfawLPJnOS5w9E6yh3pwmSroZGoHbtd Y0k3ej6J+ZoHwmc8FDskfKgsfvp/Wqb4RPXEdQcRMkUvaJDASrU07OZmZXwcngMkoHQO 3lJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=nJl4+Rte; 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 5-v6si8816274plx.517.2018.06.22.19.50.52; Fri, 22 Jun 2018 19:51:10 -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=nJl4+Rte; 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 S934711AbeFWCuM (ORCPT + 99 others); Fri, 22 Jun 2018 22:50:12 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:41109 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934663AbeFWCuK (ORCPT ); Fri, 22 Jun 2018 22:50:10 -0400 Received: by mail-pg0-f67.google.com with SMTP id l65-v6so3723312pgl.8; Fri, 22 Jun 2018 19:50:10 -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=Ivu9PS4UdgUE05m+Iz9kv7lUvuj7BkhGemCtehaD73Y=; b=nJl4+Rtehcwjp+YSrL8N9uyZWAwv0QZnaQv9JsvkHW/1xOZ95fhsSFQhMhsVb7wWZd b8EUqrctUrC8GZeQcNHMcosh1vxCglMYASPG5CPDBFehNaGpfTXQipqjpzDwgAj8b9CG +YvHE2LOageTN8Yn0dy+brT9yzBFMj+9101Z5GZ353hjjwoamTLSXEVzDfIozwTI9Iu6 kXzNLkxpKWRbRb4iA1HPdFiVfV51ZfhxRqr0l2E99QnNl7JUmZ0LbfH8nE0xTm6kcml4 kKLaIkPMLASjuIc1iM5yLNXRn5j+YbMsDjUD6u+EKuA5Y+bew7o3o3YZONCF6Rn+/pT3 tjmw== 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=Ivu9PS4UdgUE05m+Iz9kv7lUvuj7BkhGemCtehaD73Y=; b=cT7Q0klhf2HLop7YDuG8VYnHgB17Dq5z520AccNDgouKbmoeCOb4TQCYf110+a4pVe Q/K1ZdFT44dN+6Sky3ppZADzph4kHPZNTHakWCWjBZfz2K7uy5+X4lHCOInpX5YySSZw JCjizzrWmBnUDuzfjARFrHMevWgOWFhjr4yj72+IjWKtKwm3AZ72nL7ezMyYKqWZgGwu 7o4cKC6/FUp5XhB3TDlltRhlqQVJ2uqgL2L72cBmB51TCWkE+aMO6DlXf4NX4ec9v+S1 F5ssbhClXK4iURUUjP6EbGEVFAIzxU+b9SzIgM/+jcxVKetsmhMEv/ewI85fYYh4BoI/ Zkyg== X-Gm-Message-State: APt69E2POZ5ZW3EoF8W2Or+q3B8QJGZ6WM1KE/sl/lvgcDRjDgOZLINg CpQtJLNAKejtxcJb3oRkeORiCKj4 X-Received: by 2002:a65:6031:: with SMTP id p17-v6mr2635162pgu.140.1529722210243; Fri, 22 Jun 2018 19:50:10 -0700 (PDT) Received: from localhost (g134.124-44-9.ppp.wakwak.ne.jp. [124.44.9.134]) by smtp.gmail.com with ESMTPSA id y23-v6sm18804681pfa.73.2018.06.22.19.50.09 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 22 Jun 2018 19:50:09 -0700 (PDT) Date: Sat, 23 Jun 2018 11:50:08 +0900 From: Stafford Horne To: Eric Biggers 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: <20180623025008.GF24595@lianli.shorne-pla.net> References: <20180623020753.27266-1-shorne@gmail.com> <20180623020753.27266-3-shorne@gmail.com> <20180623023149.GA880@sol.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20180623023149.GA880@sol.localdomain> User-Agent: Mutt/1.9.5 (2018-04-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 22, 2018 at 07:31:49PM -0700, Eric Biggers wrote: > 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). Sorry about that, I didnt notice. I will fix. -Stafford