Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3292390rwa; Tue, 23 Aug 2022 02:07:47 -0700 (PDT) X-Google-Smtp-Source: AA6agR4FIYdc7NQ7ErloIjB0hd6ZfDL3XUh/qSbpeWkYEkQhqbXoODiybO4ArK/ikjaj6isFl0lE X-Received: by 2002:a17:906:9b83:b0:730:b3ae:343 with SMTP id dd3-20020a1709069b8300b00730b3ae0343mr16217356ejc.670.1661245666990; Tue, 23 Aug 2022 02:07:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661245666; cv=none; d=google.com; s=arc-20160816; b=GZSsQhxnZ8EJMNDC+scSLb5rsRfjn62MreMe8KlK0SAFfECJYeaH67A4YLZfFqBxUg 8wtgyXHJF0MhLjjhfbOW+y0UzsH+5ajRgyMbyZyswVDF70Jjy11LKiXLm+ou1yIKsZqw EpP68pfqROEBXjiAjuGFEWrKgqx+fSotJGz+XnEZt3OL7xLRORXkz05e4ElN3m4zkszT IoD13bGsBg51Z+UyJKsxO11vZW5EdoF/3JKgGhkBeQrXycC/OfZk//TG9qUkB25oFBjg chOuaEnqk/itKJJPDTfvCUjWe8+O3hliKPgRiziMhNtYydHAZpCBYybDTt1xrTGdOENI D4ZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Z/jAZVc4jmiRSyBlOPplpbSJMha+FjslkR7wiSGZxo0=; b=zdz2Io3LQ56O/cKLScbRdH2PB6PpnUL/p8vpeByuhXdST3ZpXerwkryNsQyfanbw0D IchEmtx91XQIKeFUYilZbrcTxsoREgCA+B6/JAnqNLjk5nOVmOXFiCocS5GyYiBPkXXW Ma9YB//PiuALtijdZ3SjBea5iZtTiO7ANFNoqW+g+Jrj8fZMInZAdA/Tb3bH+YYIYpgP sQN0vuZGnE/Gh8rf5JRnkiZ73dSQK4wI3MDTkvudthtquBrmcxTZ8EWiuceUndd6LoWM j1gkXm4kjwM9fM7D353EbmSXpz9M1jXNHOvL2e9GBYBNMY/kYAHihp+bIqLJDpjnRxcV AFlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=f2LkzkHX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sc14-20020a1709078a0e00b0073d7de9711dsi5328972ejc.650.2022.08.23.02.07.20; Tue, 23 Aug 2022 02:07:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=f2LkzkHX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346523AbiHWIkT (ORCPT + 99 others); Tue, 23 Aug 2022 04:40:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345873AbiHWIjo (ORCPT ); Tue, 23 Aug 2022 04:39:44 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3977F14016; Tue, 23 Aug 2022 01:18:31 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 46C40B81C48; Tue, 23 Aug 2022 08:17:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 87CBFC4314D; Tue, 23 Aug 2022 08:17:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661242660; bh=lzzDnu9ep7+cqxHP4yyCabn1tT37/GrAU7qmCUqISIc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f2LkzkHXrGXZxBXQb68qY4KuUBx5v04Ruih/UQyZL3bCysHYSw90++Apz97MWtBBn nh1vmW7dyFKrkkTMRO3/v51JFZ/3EYH5CLbW9a/lD13IOWfAEWLEgdkh4BjCimOjV0 7XWsSrmBzq3vkOmo8hDhRFu/QtImWfrhscJVNShg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Adrian Hunter , Ian Rogers , Jin Yao , Jiri Olsa , Namhyung Kim , Arnaldo Carvalho de Melo Subject: [PATCH 5.19 157/365] perf parse-events: Fix segfault when event parser gets an error Date: Tue, 23 Aug 2022 10:00:58 +0200 Message-Id: <20220823080124.797045620@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080118.128342613@linuxfoundation.org> References: <20220823080118.128342613@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Adrian Hunter commit 2e828582b81f5bc76a4fe8e7812df259ab208302 upstream. parse_events() is often called with parse_events_error set to NULL. Make parse_events_error__handle() not segfault in that case. A subsequent patch changes to avoid passing NULL in the first place. Fixes: 43eb05d066795bdf ("perf tests: Support 'Track with sched_switch' test for hybrid") Signed-off-by: Adrian Hunter Cc: Ian Rogers Cc: Jin Yao Cc: Jiri Olsa Cc: Namhyung Kim Link: https://lore.kernel.org/r/20220809080702.6921-2-adrian.hunter@intel.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Greg Kroah-Hartman --- tools/perf/util/parse-events.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -2391,9 +2391,12 @@ void parse_events_error__exit(struct par void parse_events_error__handle(struct parse_events_error *err, int idx, char *str, char *help) { - if (WARN(!str, "WARNING: failed to provide error string\n")) { - free(help); - return; + if (WARN(!str, "WARNING: failed to provide error string\n")) + goto out_free; + if (!err) { + /* Assume caller does not want message printed */ + pr_debug("event syntax error: %s\n", str); + goto out_free; } switch (err->num_errors) { case 0: @@ -2419,6 +2422,11 @@ void parse_events_error__handle(struct p break; } err->num_errors++; + return; + +out_free: + free(str); + free(help); } #define MAX_WIDTH 1000