From patchwork Tue Jul 2 10:34:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 168307 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: 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 + 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 ); Tue, 2 Jul 2019 06:35:43 -0400 Received: by mail-oi1-f196.google.com with SMTP id g7so12618800oia.8 for ; 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 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 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: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- tools/perf/util/map.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) -- 2.17.1 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: