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=-8.3 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,USER_AGENT_MUTT 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 88683C43143 for ; Tue, 2 Oct 2018 15:49:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3FCE120652 for ; Tue, 2 Oct 2018 15:49:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3FCE120652 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728537AbeJBWdA (ORCPT ); Tue, 2 Oct 2018 18:33:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49682 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728386AbeJBWc7 (ORCPT ); Tue, 2 Oct 2018 18:32:59 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 50E6E30821EC for ; Tue, 2 Oct 2018 15:48:58 +0000 (UTC) Received: from sandy.ghostprotocols.net (ovpn-112-5.gru2.redhat.com [10.97.112.5]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3921F2010CEF; Tue, 2 Oct 2018 15:48:55 +0000 (UTC) Received: by sandy.ghostprotocols.net (Postfix, from userid 1000) id 23B722F34; Tue, 2 Oct 2018 12:48:52 -0300 (BRT) Date: Tue, 2 Oct 2018 12:48:52 -0300 From: Arnaldo Carvalho de Melo To: Sanskriti Sharma Cc: linux-kernel@vger.kernel.org, Jiri Olsa , Joe Lawrence Subject: Re: [PATCH 4/5] perf tools: avoid double free in read_event_file() Message-ID: <20181002154852.GE9457@redhat.com> References: <1538490554-8161-1-git-send-email-sansharm@redhat.com> <1538490554-8161-5-git-send-email-sansharm@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1538490554-8161-5-git-send-email-sansharm@redhat.com> X-Url: http://acmel.wordpress.com User-Agent: Mutt/1.5.20 (2009-12-10) X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Tue, 02 Oct 2018 15:48:58 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Tue, Oct 02, 2018 at 10:29:13AM -0400, Sanskriti Sharma escreveu: > The temporary 'buf' buffer allocated in read_event_file() may be freed > twice. Move the free() call to the common function exit point. > > Fixes the following coverity complaints: > > Error: USE_AFTER_FREE (CWE-825): > tools/perf/util/trace-event-read.c:309: double_free: Calling "free" > frees pointer "buf" which has already been freed. Thanks, applied. - Arnaldo > Signed-off-by: Sanskriti Sharma > --- > tools/perf/util/trace-event-read.c | 4 +--- > 1 file changed, 1 insertion(+), 3 deletions(-) > > diff --git a/tools/perf/util/trace-event-read.c b/tools/perf/util/trace-event-read.c > index 3dfc1db..6a0d0f2 100644 > --- a/tools/perf/util/trace-event-read.c > +++ b/tools/perf/util/trace-event-read.c > @@ -297,10 +297,8 @@ static int read_event_file(struct tep_handle *pevent, char *sys, > } > > ret = do_read(buf, size); > - if (ret < 0) { > - free(buf); > + if (ret < 0) > goto out; > - } > > ret = parse_event_file(pevent, buf, size, sys); > if (ret < 0) > -- > 1.8.3.1