Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2006943imm; Tue, 10 Jul 2018 11:28:56 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeVDO/VtQzvcPWA1rxEzcaWm/pusoH72C8PJNJYGV8fIuIqubiVOTAltIidhmfqY55qiY7s X-Received: by 2002:a62:4a41:: with SMTP id x62-v6mr25179610pfa.45.1531247336629; Tue, 10 Jul 2018 11:28:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531247336; cv=none; d=google.com; s=arc-20160816; b=oIGcAT6TviWFerQau40iZYVd96D7KupHey1wofGBBYubQVICdGoGHgAD9VxjFtaIzv zSGjH1LtpZDvU3aaDItAmE669L9JoEMqGCWO2n1VrG8WOH/EaWpXfhUc3fkSFrP+jECM 0KNx7Ny1iNCFNBi7rBJxFzneFunQNz/Dui82h4MEBk23anDfTDKlqAuU35WHSbsl+kHG swP27m69ZcOUcop5Az+z+r/9YU5+SitVN1+H0aPzCicniNQ6uT3mxpNw+ygYiUbAqoSk LCoTVdkcx+uPOKuVZ1Lo7UT7sEUcdxXANDvBXr5yThjCDG5j/8gFegCmHnrxVLMdE2Hy 1Axw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=Vc7ae28Peg6/7RZl8aOpSJ2zDD8KqKtvS3DnSFAexek=; b=r5bpKKZMpGw68HqF6C1KuoTViqtJ/Xvb9Q3sn9YX3zgIayEdZfl4qyGWOqLru6bZsc AoWrUGQ5wywE3nN1+sB0ueNj3LuUxcZn2WBwMErQvNWn+9HoFepESa3GKXxDfHNrVN2U OumYVFyxFnOzm0IchmRPscriFYT3d2fAlVicwXrkQ/TyqpZt39/kJh617umj0f69iRdW 9wvD9fzb6UgCdE08m3S+dvutIZJBWL90n2BI+bNdqXU0Su+2MC1iBap9kwIdGmrpDxHb i1K7X7VfWwbjJ2SMkj+vXaUghLNCkJYkhWYjIUWFAdPrQKDyvGkHfjws175gPRk+wgsb N3DQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f11-v6si16920543plr.316.2018.07.10.11.28.41; Tue, 10 Jul 2018 11:28:56 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733137AbeGJS1f (ORCPT + 99 others); Tue, 10 Jul 2018 14:27:35 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:36706 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1733117AbeGJS1d (ORCPT ); Tue, 10 Jul 2018 14:27:33 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9D33E808255B; Tue, 10 Jul 2018 18:27:22 +0000 (UTC) Received: from cervelo.rdu.redhat.com (dhcp129-44.rdu.redhat.com [10.13.129.44]) by smtp.corp.redhat.com (Postfix) with ESMTP id 73D291C5A6; Tue, 10 Jul 2018 18:27:22 +0000 (UTC) From: William Cohen To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, linux-kernel@vger.kernel.org Cc: alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org, William Cohen Subject: [PATCH] Check jvmti_agent snprintf return value to avoid build failures with GCC-8.1.1 Date: Tue, 10 Jul 2018 14:27:16 -0400 Message-Id: <20180710182716.21801-1-wcohen@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 10 Jul 2018 18:27:22 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 10 Jul 2018 18:27:22 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'wcohen@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Newer versions of GCC perform static analysis to determine whether string truncation is possible with functions such as snprintf and provide a warning if truncation could occur. The make for jvmti_agent.c uses the compiler option that treats any compiler warnings as compiler errors. For GCC-8.1.1 in Fedora 28 this causes the build to fail. The return value of the snprint is now checked to ensure snprintf produced a NULL-terminated string. If the string for the path is invalid, the code does attempt to use the string. Signed-off-by: William Cohen --- tools/perf/jvmti/jvmti_agent.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tools/perf/jvmti/jvmti_agent.c b/tools/perf/jvmti/jvmti_agent.c index 0c6d1002b524..30f14eafe4b3 100644 --- a/tools/perf/jvmti/jvmti_agent.c +++ b/tools/perf/jvmti/jvmti_agent.c @@ -227,7 +227,7 @@ void *jvmti_open(void) { char dump_path[PATH_MAX]; struct jitheader header; - int fd; + int retlen, fd; FILE *fp; init_arch_timestamp(); @@ -249,7 +249,10 @@ void *jvmti_open(void) /* * jitdump file name */ - snprintf(dump_path, PATH_MAX, "%s/jit-%i.dump", jit_path, getpid()); + retlen = snprintf(dump_path, PATH_MAX, "%s/jit-%i.dump", + jit_path, getpid()); + if (retlen <= 0 || ((int) sizeof(dump_path)) <= retlen) + return NULL; fd = open(dump_path, O_CREAT|O_TRUNC|O_RDWR, 0666); if (fd == -1) -- 2.17.1