Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9987210ybi; Wed, 24 Jul 2019 13:36:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqwMIeNxIHV5rYKWG2qQgay6l3FPTteeRTlicX6DGunIzLg0ijoVG/Nd8G/GlyMtciBFAfKI X-Received: by 2002:a65:5c4b:: with SMTP id v11mr40227565pgr.62.1564000603469; Wed, 24 Jul 2019 13:36:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564000603; cv=none; d=google.com; s=arc-20160816; b=Xt7QmJOwfwVdNGQ4Mj/3wH3rsaHUzZH0wPFbkiq50R8alEx5f3yx0QQbUQTuwo9agf KNjaXHbre3OM3fHkhBRJHsQN9K9Az3Ii1SGmoEDS/TOV6Dds3AJDXaxwMMv2E2p1sPsw Vy0XHwmc4Mz7fANSjt4f8k+otg1N3SFuZ8ZSkPDRQ8Dgg2wvcJzuJOZNe0VwnsnEKxPQ PCq/RGO5TGJIWFWyZUGKpFMhkSo6KtQV3fvTfnF29jg5pieaoIutg66ugb3VN2KQW4DS xiwqErEs2we4/arx1ngC4pPdjk6r9ivklfatn6mylc/am+C9s8HwL3GYPD3spc0aGjok CktA== 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:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=e+lqmBWqR7iinUSGQkzbIwnePBQI24XaAe/KI4SgJV0=; b=NPMoo2S5MXC+8GSsAuR6AujYcdP7TycXmKesAzkM24gsJdJ/cfknEgVnv7FLdUSfx1 QJJzuUn+r26bsyixPhjWW86xxh+GEZPr2C2eWIaty6abSL2dUuIc3l0aT/cCcskbmKRK YEB3gshWCxCkSVQPNmmMM06hOXO+CNLn7qOzok9V1yJsC5xopRyurWp76eWKysuMj430 qQbRFHg9ShyiunoSPpHWJfGrnW4jpyUMqGZTAPxEehSGdvpCbN5Q9bzKbJ/CC156ock4 quc7sI5LyjMC0dQRTLXIOEgvlsJeLoNAtyy7mJW89sj/leTo1KiCOZ3eJ6ZCOjNVQ2A7 r3/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0tA91nRO; 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 a15si3470084pgk.523.2019.07.24.13.36.29; Wed, 24 Jul 2019 13:36:43 -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=@kernel.org header.s=default header.b=0tA91nRO; 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 S2387554AbfGXTZ6 (ORCPT + 99 others); Wed, 24 Jul 2019 15:25:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:42802 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726240AbfGXTZx (ORCPT ); Wed, 24 Jul 2019 15:25:53 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 A2275229F3; Wed, 24 Jul 2019 19:25:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563996353; bh=24KKvS/5BVLuNBrRT/Ci1feReR9yLJePTHw4GykVB30=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0tA91nROyXKBRJEIyx2dqKqYCM7MLy29g7yAmp97/Rw5dlMJUQYJyAH17Gohy1vEJ b5KtXu2DfIMFFwY8OZN61uSMueV1yW8xyWqb/Vw1vUks2bfpLROaspZRplbfLoxhVk TY0Fu1modY1Hg/rgw0/rwWVneGFuycb/BCKnIYg0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Arnaldo Carvalho de Melo , Jiri Olsa , Alexander Shishkin , Ben Gainey , Namhyung Kim , Peter Zijlstra , Stephane Eranian , Sasha Levin Subject: [PATCH 5.2 066/413] perf jvmti: Address gcc string overflow warning for strncpy() Date: Wed, 24 Jul 2019 21:15:57 +0200 Message-Id: <20190724191739.908350221@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191735.096702571@linuxfoundation.org> References: <20190724191735.096702571@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 279ab04dbea1370d2eac0f854270369ccaef8a44 ] We are getting false positive gcc warning when we compile with gcc9 (9.1.1): CC jvmti/libjvmti.o In file included from /usr/include/string.h:494, from jvmti/libjvmti.c:5: In function ‘strncpy’, inlined from ‘copy_class_filename.constprop’ at jvmti/libjvmti.c:166:3: /usr/include/bits/string_fortified.h:106:10: error: ‘__builtin_strncpy’ specified bound depends on the length of the source argument [-Werror=stringop-overflow=] 106 | return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ jvmti/libjvmti.c: In function ‘copy_class_filename.constprop’: jvmti/libjvmti.c:165:26: note: length computed here 165 | size_t file_name_len = strlen(file_name); | ^~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors As per Arnaldo's suggestion use strlcpy(), which does the same thing and keeps gcc silent. Suggested-by: Arnaldo Carvalho de Melo Signed-off-by: Jiri Olsa Cc: Alexander Shishkin Cc: Ben Gainey Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lkml.kernel.org/r/20190531131321.GB1281@krava Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/jvmti/libjvmti.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/perf/jvmti/libjvmti.c b/tools/perf/jvmti/libjvmti.c index aea7b1fe85aa..c441a34cb1c0 100644 --- a/tools/perf/jvmti/libjvmti.c +++ b/tools/perf/jvmti/libjvmti.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 #include +#include #include #include #include @@ -162,8 +163,7 @@ copy_class_filename(const char * class_sign, const char * file_name, char * resu result[i] = '\0'; } else { /* fallback case */ - size_t file_name_len = strlen(file_name); - strncpy(result, file_name, file_name_len < max_length ? file_name_len : max_length); + strlcpy(result, file_name, max_length); } } -- 2.20.1