Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2652567imj; Mon, 11 Feb 2019 06:30:37 -0800 (PST) X-Google-Smtp-Source: AHgI3IY0qvK2Mg1IGNLpZeXCFdgBqj37V/JHhedDq2B5dfJzUVOeRXXX/zGBE2i9SBVSFkYflsm0 X-Received: by 2002:a65:4381:: with SMTP id m1mr33047598pgp.358.1549895437351; Mon, 11 Feb 2019 06:30:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549895437; cv=none; d=google.com; s=arc-20160816; b=rJPWM2muy+HuYBHANfQq2pTui6wySu4/AXcOcCemTtNSW7xxk6fvH5DL0sMoXt6rOv kVzK9I+0/SQuoB9heqsKg6RaRg2ZiSi234LixGgOAYYG9WwVmrMxM4saZNWEJn4Fwxh7 hIeqqZqignmcr3OnVVOTXwcFKmpz4e2Y7yNzmojPjTmq2tmBFAs13ePaIcYXBAmL5hjJ bW0JEEVMQrQBDSbW/g1trvQZ8Y/5lH2BZTG8B3LWwjXh88TQZNgr6jX7UTO2/abTWL3h ksa2xpUx6LW+aDi1X2Cg/YjrPKujgnE36pStYfioAkw55efsnx50oqwaZNMnO+zenCms YSyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Z5ZirL+qnEJPEG2eQBywo3hiAgI/9vjUdhnDQuAP82k=; b=PaHaFOT3YjOz/fMgiHdsiOYEZg5cRPO9CvHx3h41s9bhfA9awv1BTuDXFCBDluoV3f bg9mKDY7Ajrx1qXIDWPWgl9c5AjkYzEp+gi4w7iDZbZ1d3ole8EvM1gLCocCgMjEmCnv G5Jneh2graB65hKFdZ3ceYzYfMxxmwI1a4YWKcpKknW6FiN3J1tSdeOJuUQ1oSDI2CKU l3FVMu3jzAclWHH05J6FmxvKQTGoirTCveKvdkf2emLlQb42BOpTE36EvKyriBy9rHJp EF1HG4XDSSB++K1oeNY+BJPjyGxQNBHYBkLF5LjjzSg4mQvNcsJkOaZVrLpWCnX0sb12 svyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=y7jwxC91; 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 f124si11082394pfa.1.2019.02.11.06.30.21; Mon, 11 Feb 2019 06:30:37 -0800 (PST) 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=@kernel.org header.s=default header.b=y7jwxC91; 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 S1730029AbfBKO3r (ORCPT + 99 others); Mon, 11 Feb 2019 09:29:47 -0500 Received: from mail.kernel.org ([198.145.29.99]:35880 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730020AbfBKO3p (ORCPT ); Mon, 11 Feb 2019 09:29:45 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1D99C20675; Mon, 11 Feb 2019 14:29:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549895384; bh=rTQ1VR6/QIOGmKCRJ/pqxfp4QwvGEmI2GenRRCqKYgI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=y7jwxC91nhkn0EuPbHJY6vP0s4za+h+NwctpneKtuGHgAUasUpDc49TejO3kBK1cW IxsBcUMveYd/bH3p04nqoWNknVlg3pr59Hgjg/PVS8C0Z5mxOISvqOgHtEaIX1bQr8 u745JHLyFghZsyCrBs4pnBhrVQ6PJsRGW3rIHFtA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Adrian Hunter , Jiri Olsa , Namhyung Kim , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 4.20 188/352] perf header: Fix unchecked usage of strncpy() Date: Mon, 11 Feb 2019 15:16:55 +0100 Message-Id: <20190211141859.079329086@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190211141846.543045703@linuxfoundation.org> References: <20190211141846.543045703@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.20-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 7572588085a13d5db02bf159542189f52fdb507e ] The strncpy() function may leave the destination string buffer unterminated, better use strlcpy() that we have a __weak fallback implementation for systems without it. This fixes this warning on an Alpine Linux Edge system with gcc 8.2: util/header.c: In function 'perf_event__synthesize_event_update_unit': util/header.c:3586:2: error: 'strncpy' output truncated before terminating nul copying as many bytes from a string as its length [-Werror=stringop-truncation] strncpy(ev->data, evsel->unit, size); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ util/header.c:3579:16: note: length computed here size_t size = strlen(evsel->unit); ^~~~~~~~~~~~~~~~~~~ Cc: Adrian Hunter Cc: Jiri Olsa Cc: Namhyung Kim Fixes: a6e5281780d1 ("perf tools: Add event_update event unit type") Link: https://lkml.kernel.org/n/tip-fiikh5nay70bv4zskw2aa858@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/util/header.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 4fd45be95a43..13a2251a37c5 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -3544,7 +3544,7 @@ perf_event__synthesize_event_update_unit(struct perf_tool *tool, if (ev == NULL) return -ENOMEM; - strncpy(ev->data, evsel->unit, size); + strlcpy(ev->data, evsel->unit, size + 1); err = process(tool, (union perf_event *)ev, NULL, NULL); free(ev); return err; -- 2.19.1