From patchwork Tue Jul 2 10:34:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 168308 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp4072656ilk; Tue, 2 Jul 2019 03:35:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqz2FJ9f0jzftT9qDmrsPFXr3dgouJ/8pn4zmQUpXZf0dSWMqEfoUvc5Nr1UW4YwcK6wiK8R X-Received: by 2002:a17:90a:2486:: with SMTP id i6mr4736545pje.125.1562063744336; Tue, 02 Jul 2019 03:35:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562063744; cv=none; d=google.com; s=arc-20160816; b=WbXTPf2nNH8ApJVyBDVEmGgG5oUCxHVuJYZrzZlwt2Hkr3CQ2c36hbacOoub1tu1ws pYShXCDFExQ6MgE266Vw+coIAijzj00aK25WbFTu+qkmsEchO4T4nSVAiJhq391In3CN 71+sNaR11zMPVxcWRezLHHpcy5W8PvK9hsQP0GEhF6V0bRFoaCj2YLcT2jzE6JEb8PLM V0AZ+Su7RHuIdvoZWrcIK0Q19Y29AA8g2eGc5gVWV+KO3C20NADCRjJpI0jZ9q9p1Xjh FAho4xLA1a41wY/aiD5nLxaKUVT9bjf2wNuAGBMjFEZnYLCpqsSeUotKnO133KiOfGGw K7TQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=Ntf4e24cY15lCTdagT3iS0+VMjBOYWf7Iw92R3PEKUw=; b=vglpgDgmnXGpXUCVZWkQ+T53jqY02b2VR88XxW7RCBL0Y2NqriPwBpkN4hoVqiZ7B3 qjQFN9EGMOd9maQLGeNM6qx68O3JdluUbR91iIHSkwbdSBT8mqEckPeAk64Rg419KTaF SaIbiLkkDM65NqGpWYou0cQHk3Wlj+SFeZ/+hlvYJZP7TD6Z6zHBrPwHdOC9+gS0stgP ssF9L94NqofIQAWCkdcd9QYhsBkgnqe+njckVflExoSRMna5ALnOMP2ZzK+Z5/Yvysqg tX6ULq7wWnO8AAHqGWcYF6ovHW+IoJ4ej59lBRhojIKVa0Or5r/QCq/UL5Mbhd+X+mkh f7rQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BFh3rrWH; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j23si12421035pll.214.2019.07.02.03.35.44; Tue, 02 Jul 2019 03:35:44 -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=@linaro.org header.s=google header.b=BFh3rrWH; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727218AbfGBKfT (ORCPT + 30 others); Tue, 2 Jul 2019 06:35:19 -0400 Received: from mail-ot1-f66.google.com ([209.85.210.66]:33543 "EHLO mail-ot1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725801AbfGBKfS (ORCPT ); Tue, 2 Jul 2019 06:35:18 -0400 Received: by mail-ot1-f66.google.com with SMTP id q20so16655149otl.0 for ; Tue, 02 Jul 2019 03:35:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Ntf4e24cY15lCTdagT3iS0+VMjBOYWf7Iw92R3PEKUw=; b=BFh3rrWH1Q7vw8K9KiTKC5WaEVtLH0hxOlQ8lYb+DxjHbhrG8G/LElcvUvV9Z5bMjY PvFP3WCg4pEAT++5wHCFpR6vuJg14wqFr8xkqfLzZtDJAbaIKzIL7uG+cj1GqzhMO2oz lWopsH2r9uZgOt0L6Hl1QCAUtH7Cy7js2lqRCrJnKKpRi0tuHwlSYpEodH9GQE/iUnc2 FTPTtbK8H85AKdlBWYas0YUdufWuQAxbJ10khbih9MAd2Fmr+Mu5q6+8HCD70UpIv4LS kxPqAejefCAGovMeEGJzkcsjEhjSPfW3Vd90Z4GpmBWL3WYYkgjneF7Yov6E3seeRjaq gy1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Ntf4e24cY15lCTdagT3iS0+VMjBOYWf7Iw92R3PEKUw=; b=OKHJaSxIPBv3/GJBkw5vPJuydtvu6d/t7FjwStj8OU0XvM+WqCHQEhlddHz9LFAxs8 FamvqslAQJqmCHmKpwSGdN13o5NCfWrHzAQDBFyJkF9nVQuDPBRZv6hYgFgunDX0KnU0 sbRAoD6U3WJ4jPWU5w0ngNwm0wgEwITxGDuSCblvQZjyQBkwV8dI7yjyJbzPc/gf4VJg 8zZMOEV+Uya6Jhnj7WylfRNhHqf4PsG2SHFxwYWTRTX5fhyBsph6fnEXh9eQ0OfsTovJ 5aF1ClEbPpuJKXyPZdrldtokJYVgwV64MnlH+MEBQD93k5T+mE+0HRBozUXKJ3fu5DS4 kuAw== X-Gm-Message-State: APjAAAV9m8BxyBGbznD2w5YKp+DULzrcihmx6empNVpBdfYCXQ6L7UwB 4F1bPOGi5UB41dfW6Qdr3zGRXA== X-Received: by 2002:a9d:6853:: with SMTP id c19mr1570455oto.213.1562063718005; Tue, 02 Jul 2019 03:35:18 -0700 (PDT) Received: from localhost.localdomain (li964-79.members.linode.com. [45.33.10.79]) by smtp.gmail.com with ESMTPSA id 61sm5139805otx.8.2019.07.02.03.35.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jul 2019 03:35:17 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Peter Zijlstra , Ingo Molnar , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Mathieu Poirier , Suzuki K Poulose , Andi Kleen , "David S. Miller" , Davidlohr Bueso , Rasmus Villemoes , Jin Yao , Song Liu , Adrian Hunter , Alexios Zavras , Thomas Gleixner , Changbin Du , Eric Saint-Etienne , Konstantin Khlebnikov , Thomas Richter , Alexey Budankov , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Leo Yan Subject: [PATCH v1 04/11] perf annotate: Smatch: Fix dereferencing freed memory Date: Tue, 2 Jul 2019 18:34:13 +0800 Message-Id: <20190702103420.27540-5-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190702103420.27540-1-leo.yan@linaro.org> References: <20190702103420.27540-1-leo.yan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Based on the following report from Smatch, fix the potential dereferencing freed memory check. tools/perf/util/annotate.c:1125 disasm_line__parse() error: dereferencing freed memory 'namep' tools/perf/util/annotate.c 1100 static int disasm_line__parse(char *line, const char **namep, char **rawp) 1101 { 1102 char tmp, *name = ltrim(line); [...] 1114 *namep = strdup(name); 1115 1116 if (*namep == NULL) 1117 goto out_free_name; [...] 1124 out_free_name: 1125 free((void *)namep); ^^^^^ 1126 *namep = NULL; ^^^^^^ 1127 return -1; 1128 } If strdup() fails to allocate memory space for *namep, we don't need to free memory with pointer 'namep', which is resident in data structure disasm_line::ins::name; and *namep is NULL pointer for this failure, so it's pointless to assign NULL to *namep again. Signed-off-by: Leo Yan --- tools/perf/util/annotate.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) -- 2.17.1 diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index c8ce13419d9b..b8dfcfe08bb1 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -1113,16 +1113,14 @@ static int disasm_line__parse(char *line, const char **namep, char **rawp) *namep = strdup(name); if (*namep == NULL) - goto out_free_name; + goto out; (*rawp)[0] = tmp; *rawp = ltrim(*rawp); return 0; -out_free_name: - free((void *)namep); - *namep = NULL; +out: return -1; }