From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 55DD5C606BD for ; Mon, 8 Jul 2019 15:43:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2EAFE20665 for ; Mon, 8 Jul 2019 15:43:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562600611; bh=/8nzzgTpLpo7FUdm6nCfC8NOHzv5gXsTv6CLp9XYgAc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=pVlrWNUeAmsJaNOxcPDuaT8Zklf4WLGz41EnSD1cYVlIQhZoWscY36SC7eCP1OU1D vjcHXNf//x2X1wOy28DxmC3G7ROGwGwfUASFoI+mhmKsCXi9WpA1gxbW9sS/iRJpM5 oF5aR3s/CoDZgDUDk9fo1tqvJ1PP9GMyFqVjeGOQ= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2403838AbfGHPna (ORCPT ); Mon, 8 Jul 2019 11:43:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:43686 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729890AbfGHPnZ (ORCPT ); Mon, 8 Jul 2019 11:43:25 -0400 Received: from quaco.ghostprotocols.net (179-240-135-35.3g.claro.net.br [179.240.135.35]) (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 87ED421783; Mon, 8 Jul 2019 15:43:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562600604; bh=/8nzzgTpLpo7FUdm6nCfC8NOHzv5gXsTv6CLp9XYgAc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IaJZWXCs2J7G54N6J8XUZEwB1FoHSTZRUkOL2r4NDSUac3Zw09OFJcRPl8tcBtfRU +wQh2p9p29r/RM3KXAuT3W8MYMAnygkSR8pMDgWaF+8S11gz62hWk/qgUupSgelsdx GOointIzG1xHq9Q06mr4qE4k3woD9e29WIXdq0BI= From: Arnaldo Carvalho de Melo To: Ingo Molnar , Thomas Gleixner Cc: Jiri Olsa , Namhyung Kim , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Jiri Olsa , Arnaldo Carvalho de Melo , Alexander Shishkin , Ben Gainey , Peter Zijlstra , Stephane Eranian Subject: [PATCH 8/8] perf jvmti: Address gcc string overflow warning for strncpy() Date: Mon, 8 Jul 2019 12:42:07 -0300 Message-Id: <20190708154207.11403-9-acme@kernel.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190708154207.11403-1-acme@kernel.org> References: <20190708154207.11403-1-acme@kernel.org> 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 From: Jiri Olsa 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 --- 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