Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3701527imu; Mon, 28 Jan 2019 09:16:51 -0800 (PST) X-Google-Smtp-Source: ALg8bN6XUfkQgxNSvrufjjYObp1QWWaxU1Ipkhuipkyu1d8y571IzBj41dmV4saVuwjepOTmqQv/ X-Received: by 2002:a63:7a09:: with SMTP id v9mr20671691pgc.112.1548695811256; Mon, 28 Jan 2019 09:16:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548695811; cv=none; d=google.com; s=arc-20160816; b=FnPw43JYY2t2pJdSpRDqXqZNZ7S9MHtwf2kBPf+9aQaaq0YA+rWW30N1qW5XrgJkfJ qroSl3kx7bVR/RluglxufD5AKvMLT9JuBm5LMmyfEl+UBI7YPbLIXeC+kGeCe9W9IuI8 SwGzs9u9BUGs6B0hsvQPkjliSM7AOUxJ7Ua8blGO6AyIlymaruazTmrsGegiRomtVBZ0 4UJYl/jHSJK/e6zqhccOJZ7cKoAmQPkmcausC16nUwhGyqfsR5cW/81Os0Es9jd+QXNV Y0p5KlcHhG56dbwHtEV0K1pYaK+s0tEuxtmW0bT5LrfuDu+WfTJJPuD3w8yQoAf8nhbj qMag== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=rwASG4+7wLjO3qbggLoDF96QZjYZdfhFz3oZjmS3vJM=; b=FlmEDmCeJVa6iiAGNIuEmbrox7Wk3aY5Uah2hxn3eMO7b3Qzfh4FDpGfA7Cb7JM2Qf kesN36m7A/gt3sEZmkV4io0aNFC9klbHBDVqZlNDibfg85Z6YaWXgys3lNdnApcj1KME zcIi/nTHwTEZOfIGY8J64lF85BGPegLAAqHFLlM0hvBWeSSp+mAiO/TOwZBDjv1brw0q 6i5wXOn3nDa+JcQtI+fCeZNfCP9aTOqJvUnUWRSZUk/kSvFH0uZ7k6HeoZm4YL40CEau HGF1FLYVefjVGTDuuadzu4goDeNP9MmNdWWkOAUSsJZVX9nNwsgpDKzAkmqiOYX1gdB8 mW8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tM2eHIsg; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i129si36322831pfb.32.2019.01.28.09.16.35; Mon, 28 Jan 2019 09:16:51 -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=tM2eHIsg; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732178AbfA1QHV (ORCPT + 99 others); Mon, 28 Jan 2019 11:07:21 -0500 Received: from mail.kernel.org ([198.145.29.99]:57628 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731457AbfA1QHQ (ORCPT ); Mon, 28 Jan 2019 11:07:16 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1E67D21738; Mon, 28 Jan 2019 16:07:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548691635; bh=8ZmDIZ6VnhE1oKTf8i6oTTm6RaoRu50baI3nIspR09M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tM2eHIsg6tershWdrbRdLbBU56/MgWc7nAy66pEwlvjVYsXxcTJzToBeKbgi3rAwv zBe2H0sWKglGKgqIhV7x5eJpKmGRQNuqEq1lhzsuSxOXG90zWUr6NPJ/47ZbBFAzvl KI1NKyw4R70JY2FhhwyvW/d7exfXKZl5HPfmBJ7A= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Arnaldo Carvalho de Melo , Adrian Hunter , Jiri Olsa , Namhyung Kim , Sasha Levin Subject: [PATCH AUTOSEL 4.19 167/258] perf header: Fix unchecked usage of strncpy() Date: Mon, 28 Jan 2019 10:57:53 -0500 Message-Id: <20190128155924.51521-167-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190128155924.51521-1-sashal@kernel.org> References: <20190128155924.51521-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Arnaldo Carvalho de Melo [ 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 3cadc252dd89..ac3c59e7da16 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -3521,7 +3521,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