Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2685008imj; Mon, 11 Feb 2019 07:01:23 -0800 (PST) X-Google-Smtp-Source: AHgI3IYcE+IDM/A9ixuMCElvT2nQaCVOXiM/4I7HoSdQMsC2jbv3JtyacRSvydYWLHdS4GoiQWKp X-Received: by 2002:a62:9917:: with SMTP id d23mr19003153pfe.88.1549897283421; Mon, 11 Feb 2019 07:01:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549897283; cv=none; d=google.com; s=arc-20160816; b=XYWre23Qa7294TODJXx+1sHzOjAAH3HjFzVWA9sVihCchngqO5g6GCGMgiJqlGtGp7 EW0Z6B4vVwcniPl+zOuYnGS7bvHbiJAMa13aFvvlHsq08hg5ELSS7VbjcHrNSS3HY96X W3WzdZbC7EvVeS265/Djim21r6DFOjwTk5Ihu5mwiNlyK1WcE9UQ4BPop2WjL8Jm8uTL zT9w1ynpnvbqe3s53FQweD7R9L54slt0v4tuLnwhdfUnBaoR63alxFL1jD8BwOQDBEtx DgFJd6QBSXtXc7x1iMhiW0z/kSc0uEtVhBv4+guKiF/fI4SrtEhGhhMyxkJzcO++4G3T f9gg== 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=k2MoZtDrhqHgexmIy/mw0ub9vGorwvCvBiA/28wnVIE=; b=yUPa0S0wIL1KC9hi/QC9G8YwD+ZEmQ7bodPXnTnXZZeX4s32u94sqVhjK2EmaU7tpx Fe7OsMocdzQLTyR4XvSJ+sOvCjlD+V5YYHrqjFAjHmd+MPnCjHhfgeX5Zber1jvbKYhx MB/kff3iALNjbv2+ueRS2ot5FNjiLGUDs/2oycteLTMhcaXNkiTMYY5bB4vrtRD08Gil z3IC8H41sE/0KmkZx3xNdyL/6NhFy09N+mDTLBbDsSgPKpIR5htVqlc7MZhrjDt7ng3P 59amejqVe6A1xFKXpwHdd85a93YD6GsZDXUUs58qmn/vJnufkHloIXflLO6utLU9xEtL kktw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Uk3q62GT; 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 206si9621065pga.240.2019.02.11.07.01.04; Mon, 11 Feb 2019 07:01:23 -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=Uk3q62GT; 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 S2388969AbfBKO6y (ORCPT + 99 others); Mon, 11 Feb 2019 09:58:54 -0500 Received: from mail.kernel.org ([198.145.29.99]:46616 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389639AbfBKO6x (ORCPT ); Mon, 11 Feb 2019 09:58:53 -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 19C2B20700; Mon, 11 Feb 2019 14:58:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549897132; bh=J6yntQty4gXnwRFpilyyK6sIYi35WUgUPKSC/UVE88o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Uk3q62GTpn2C6bcO5nnR7oswq+VRMYNPJUv0hD0U4Xf5HR3LBLft95t/gR9FjK9nY KhN9FoCQw0UeCX+KQodOjg8Chsb5IZTy2PNpGtA0aTXP2Mp+iO4WdQhrDiRt4knfOU r+vLvGNRgrR41dPXd1ETwlv5GmwSotNYtWF8sy/M= 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.14 102/205] perf header: Fix unchecked usage of strncpy() Date: Mon, 11 Feb 2019 15:18:20 +0100 Message-Id: <20190211141835.268467154@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190211141827.214852402@linuxfoundation.org> References: <20190211141827.214852402@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.14-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 1ceb332575bd..696f2654826b 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -3132,7 +3132,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