Message ID | 20190702103420.27540-8-leo.yan@linaro.org |
---|---|
State | New |
Headers | show
Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp4072755ilk; Tue, 2 Jul 2019 03:35:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqxkaAW9B0RvahcV9HMUuCboAwhvCXaItFOZZkwEXwQKzVnarkCFWF886RcoZoGPwHTQicXo X-Received: by 2002:a63:d4c:: with SMTP id 12mr30739401pgn.30.1562063748450; Tue, 02 Jul 2019 03:35:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562063748; cv=none; d=google.com; s=arc-20160816; b=GeosI96sXnSVO0kX3MJjngIVbYWoBWihsu7HkXOMHoCUnXJn6VSeeEZ6H06U3FEzRe n8mj1ibXdyrTgJEW3pyRvb664kDgi2HrvsnTEaUFvCZ2Y2yQ+ZEQtbOezAeB795SKSi8 qo/Dk4Eprs2AqwZbc4x5G/UY7QEmxm4NbiEmsDsYDS0bseZKQvxlWIwbYJB7IlmEJk2u ahkBgD4uF0paSj8OREXBPeXhv//ipLBezdkxCFmPbBj5uK4F23PBtEqYMdXzYHBdI1pq tJBiD2sPZ3Q931pdMLa/yk2go0EI//BwgNDCwAznngkLlJ1unjvAZfvsbUvZQeW3r7Mc I/Kw== 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=V5qTJJXMX1ZTj5uDhYEBO+OiJyquQwYXAx7tq46WL+E=; b=Cv8IFEhZyCC3pwNgGnZm5VcMhnwXkwBOwuBqFc1WqCfOofIg7W83ce1jGVYZnM1zfe XdgAmmy+LtZXD56h6Js79HuQQFPFHaReetLaTXkEK+JtpO4lU1hzz43KF9gKE2Rmsiag T3le2z/f1TGP9b0/bdKh31wt3k4oVijCmeV9FA+p6QedP6fLuv+yLN20rOnhod5c8+C4 I2jsYB16RS0ktYik4Ha30130Si1ddmozLy2RJICA95rnSHeol+vyNTEgM+Z++uJPlm7l vyJbbcNko9twn9q9uLeomrwBR05FEtU64jA9iNjaOTaONu5OKPAvPK2LUbBvzxGY1C/L KFyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kl6cvJ0z; 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: <linux-kernel-owner@vger.kernel.org> Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s18si12326007pgj.541.2019.07.02.03.35.48; Tue, 02 Jul 2019 03:35:48 -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=kl6cvJ0z; 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 S1727314AbfGBKfo (ORCPT <rfc822;mike.holmes@linaro.org> + 30 others); Tue, 2 Jul 2019 06:35:44 -0400 Received: from mail-oi1-f196.google.com ([209.85.167.196]:41393 "EHLO mail-oi1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725801AbfGBKfn (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 2 Jul 2019 06:35:43 -0400 Received: by mail-oi1-f196.google.com with SMTP id g7so12618800oia.8 for <linux-kernel@vger.kernel.org>; Tue, 02 Jul 2019 03:35:42 -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=V5qTJJXMX1ZTj5uDhYEBO+OiJyquQwYXAx7tq46WL+E=; b=kl6cvJ0zlfJ4KIzgl8/M2GfhjusvmgoE9v0c+xjgfAU4sjiJCtTNEv2yzhWtVB8AI+ gVbM8Qqsd7hSC9h0YewLPNreo18mQdKFVsH7a/QDGIyl2Bx1MoYHbh/qxkHoMHpiHQQZ vGOf5QD+aLwBNctZy/pFQEZGJbP+OIpBoWjVd7U6ksXP+Kq7VHvzUoFQcrbYXG+R4IXC T2VkFAs1O1gftEP2gLOO9Rw0MVuxO3GxyeHuurTVufDtKMAqN1fYRoKPEeS15cpCs1uV ZLkVdcbR1CFwm0XLj32S+RmS5gWwfsNv0VOqqgjvUahAMaBkQgFnEolKo5Cz/8uEdTmr yehA== 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=V5qTJJXMX1ZTj5uDhYEBO+OiJyquQwYXAx7tq46WL+E=; b=acWDy8EZ1JCm0F7Ic8GDu20suVPFVL2KVuU0akvDhGmmrCHD+cGVP1Qm+WHqk9wLh9 wyWzzx13n7d94PDcJAi3RrA4eBhLkKnqFPgUXqIgNkeSVC65tXnjofpq96WWajClOTqE G3/lQonenCugIJ5rPg+PYaMyOVnzhP4mo/ObB0eCTwqaw1JQXnms17K8AsekHZMF37yl /u0iJO01doXDJx0eDcSSvgXDLkMd9ZvYEhbJW8T8TvjyflUQRMOqqtxxVX5i5zpKmqVu Jcud13un8Ld8PwHGpuRY6RMdmO96Fs5LrNjLHsIU4VCdkoTceYiYSPoo0cMssK9GAb7Y DFiw== X-Gm-Message-State: APjAAAUSOmd78AD2lj4FQRIzyQCKtxZGO2ZBNEZIGvv7tRknUp+MW0MI BMZReAQDJ4MBycDdpNfMJ56Omw== X-Received: by 2002:aca:c5d0:: with SMTP id v199mr2313436oif.144.1562063742299; Tue, 02 Jul 2019 03:35:42 -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.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jul 2019 03:35:41 -0700 (PDT) From: Leo Yan <leo.yan@linaro.org> To: Arnaldo Carvalho de Melo <acme@kernel.org>, Peter Zijlstra <peterz@infradead.org>, Ingo Molnar <mingo@redhat.com>, Alexander Shishkin <alexander.shishkin@linux.intel.com>, Jiri Olsa <jolsa@redhat.com>, Namhyung Kim <namhyung@kernel.org>, Mathieu Poirier <mathieu.poirier@linaro.org>, Suzuki K Poulose <suzuki.poulose@arm.com>, Andi Kleen <ak@linux.intel.com>, "David S. Miller" <davem@davemloft.net>, Davidlohr Bueso <dave@stgolabs.net>, Rasmus Villemoes <linux@rasmusvillemoes.dk>, Jin Yao <yao.jin@linux.intel.com>, Song Liu <songliubraving@fb.com>, Adrian Hunter <adrian.hunter@intel.com>, Alexios Zavras <alexios.zavras@intel.com>, Thomas Gleixner <tglx@linutronix.de>, Changbin Du <changbin.du@intel.com>, Eric Saint-Etienne <eric.saint.etienne@oracle.com>, Konstantin Khlebnikov <khlebnikov@yandex-team.ru>, Thomas Richter <tmricht@linux.ibm.com>, Alexey Budankov <alexey.budankov@linux.intel.com>, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Leo Yan <leo.yan@linaro.org> Subject: [PATCH v1 07/11] perf map: Smatch: Fix potential NULL pointer dereference Date: Tue, 2 Jul 2019 18:34:16 +0800 Message-Id: <20190702103420.27540-8-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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org |
Series |
perf: Fix errors detected by Smatch
|
expand
|
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c index 6fce983c6115..5f87975d2562 100644 --- a/tools/perf/util/map.c +++ b/tools/perf/util/map.c @@ -476,8 +476,11 @@ int map__fprintf_srccode(struct map *map, u64 addr, goto out_free_line; ret = fprintf(fp, "|%-8d %.*s", line, len, srccode); - state->srcfile = srcfile; - state->line = line; + + if (state) { + state->srcfile = srcfile; + state->line = line; + } return ret; out_free_line:
Based on the following report from Smatch, fix the potential NULL pointer dereference check. tools/perf/util/map.c:479 map__fprintf_srccode() error: we previously assumed 'state' could be null (see line 466) tools/perf/util/map.c 465 /* Avoid redundant printing */ 466 if (state && 467 state->srcfile && 468 !strcmp(state->srcfile, srcfile) && 469 state->line == line) { 470 free(srcfile); 471 return 0; 472 } 473 474 srccode = find_sourceline(srcfile, line, &len); 475 if (!srccode) 476 goto out_free_line; 477 478 ret = fprintf(fp, "|%-8d %.*s", line, len, srccode); 479 state->srcfile = srcfile; ^^^^^^^ 480 state->line = line; ^^^^^^^ This patch validates 'state' pointer before access its elements. Signed-off-by: Leo Yan <leo.yan@linaro.org> --- tools/perf/util/map.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) -- 2.17.1