Received: by 10.213.65.68 with SMTP id h4csp13705imn; Mon, 19 Mar 2018 17:54:57 -0700 (PDT) X-Google-Smtp-Source: AG47ELus4WcJtYtfK9WsDZyngiKxvnnaa9Z4scStcqfDI2XW92cfzJ+XvDS3SCsXOx8JTBQOFrTW X-Received: by 10.101.98.137 with SMTP id f9mr10422504pgv.6.1521507296983; Mon, 19 Mar 2018 17:54:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521507296; cv=none; d=google.com; s=arc-20160816; b=N5AHW86sn/KtCUskW5DdX0LGgaKO7MyD9Umw+ySOmaZSYXq4yvj+5C5dPctHAmf8R8 NJ/DSwAjNEDF96TrrZmnU1Eoa3NUBv6/Y31oHVAVhKgGkginbZmGq5LRO5a5EtJN6rd2 vkUmqG0DTNscIEOaKtyvkaTt7o9Vxx8NOaJUud797PI4C/NtLS3iWamknSDk3y9eOtfX fPA/Fdo/FUwIcwiBs3pbjV19PHUSFRNSjnaC5ZFKdCz08V3gqOgi6kOfeMWqOZYisZD8 z/wZ3eKPFwoq4zgfWRTXXoIWs5KeEfl6uwEHG4RAjaSN0syJcODaa8AvU1n41kFGMFSt mEpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=s6SjzCic3RjrWlRQ1eD9sWaxqbiLJ0aZnln4xRFaJas=; b=TUVJQZoZL/eVkUQTNGafwY0p2GShsFGtfsz+d+7QU9zKPib6IWmNbBU7+UE6GxT9JV VxipMDc2Uf4HW2yGDtO9VSnpR2udydRzoDzsRGjIDWnXUXuE+FSyNrx864jHMRPaNVn2 vTA/7n0MPWFj2TO9k+GSORaaozvee/LtBQYztGiu/GNM6HM5AZHBuQMnkMDle29a3hIp 5mHz31psacpwEzSRtcwYWIU8Jg4oV4/FO2E52eeCowjupCbzON7AG0v/5jOqfSz1AP+3 +hjJcHz0sJl/0BO9X3QsxJd3k6B+ilxpvnAV8DGtRyjYYliX6VYNqcyzMtKa8gGsok0x +V/Q== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t23-v6si454643plo.637.2018.03.19.17.54.43; Mon, 19 Mar 2018 17:54:56 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1031333AbeCSSWo (ORCPT + 99 others); Mon, 19 Mar 2018 14:22:44 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:48574 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1031289AbeCSSWd (ORCPT ); Mon, 19 Mar 2018 14:22:33 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 86274129B; Mon, 19 Mar 2018 18:22:32 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tommi Rantala , Alexander Shishkin , Peter Zijlstra , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 4.9 069/241] perf buildid: Do not assume that readlink() returns a null terminated string Date: Mon, 19 Mar 2018 19:05:34 +0100 Message-Id: <20180319180754.063574728@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180319180751.172155436@linuxfoundation.org> References: <20180319180751.172155436@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Tommi Rantala [ Upstream commit 5a2342111c68e623e27ee7ea3d0492d8dad6bda0 ] Valgrind was complaining: $ valgrind ./perf list >/dev/null ==11643== Memcheck, a memory error detector ==11643== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al. ==11643== Using Valgrind-3.12.0 and LibVEX; rerun with -h for copyright info ==11643== Command: ./perf list ==11643== ==11643== Conditional jump or move depends on uninitialised value(s) ==11643== at 0x4C30620: rindex (vg_replace_strmem.c:199) ==11643== by 0x49DAA9: build_id_cache__origname (build-id.c:198) ==11643== by 0x49E1C7: build_id_cache__valid_id (build-id.c:222) ==11643== by 0x49E1C7: build_id_cache__list_all (build-id.c:507) ==11643== by 0x4B9C8F: print_sdt_events (parse-events.c:2067) ==11643== by 0x4BB0B3: print_events (parse-events.c:2313) ==11643== by 0x439501: cmd_list (builtin-list.c:53) ==11643== by 0x497150: run_builtin (perf.c:359) ==11643== by 0x428CE0: handle_internal_command (perf.c:421) ==11643== by 0x428CE0: run_argv (perf.c:467) ==11643== by 0x428CE0: main (perf.c:614) [...] Additionally, a zero length result from readlink() is not very interesting. Signed-off-by: Tommi Rantala Cc: Alexander Shishkin Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/20170322130624.21881-3-tommi.t.rantala@nokia.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- tools/perf/util/build-id.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) --- a/tools/perf/util/build-id.c +++ b/tools/perf/util/build-id.c @@ -182,13 +182,17 @@ char *build_id_cache__origname(const cha char buf[PATH_MAX]; char *ret = NULL, *p; size_t offs = 5; /* == strlen("../..") */ + ssize_t len; linkname = build_id_cache__linkname(sbuild_id, NULL, 0); if (!linkname) return NULL; - if (readlink(linkname, buf, PATH_MAX) < 0) + len = readlink(linkname, buf, sizeof(buf) - 1); + if (len <= 0) goto out; + buf[len] = '\0'; + /* The link should be "../../" */ p = strrchr(buf, '/'); /* Cut off the "/" */ if (p && (p > buf + offs)) {