Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2401700imu; Thu, 24 Jan 2019 12:08:11 -0800 (PST) X-Google-Smtp-Source: ALg8bN5rsxYzrBrF78EdVjaHsTJCBGxZlKG0RyKz0NNKZmQ4uoZEQD+oYS4au5ac9Ybx2G1MSr81 X-Received: by 2002:a17:902:29ab:: with SMTP id h40mr7878380plb.238.1548360491094; Thu, 24 Jan 2019 12:08:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548360491; cv=none; d=google.com; s=arc-20160816; b=mRikpjZVltldkbXnrhEVIsUxvgPfWTN8ppveQD1PVJ7576EGtZ9yG//XmexCKGKeJZ 3N1G/yIZH0C1EeI3DaYoqQ+k62j73Ym6wPMpqOXEAH6c7YxEzD4QxLWWDaFrBaHh2om+ SoziUFJy6JHyiq4sFXXS/d+3B9J7D9HBC6ixyXbpicWvVXcNsFsEdvyCr5woytgfBmrK iZpdBKgmyxbIykzE+zbMtEHI6OqRiIiaBnyx1xtYFmr6Knf/5WCj1ysYakeK7vCwQMqS XOElDtpLGJ3gqybw2uETb4ptN27XJRJl9jzWWijywNws4IoByqcyvwA3q8Oo9O8mVVW6 Qn1Q== 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=as8mWTzBPdRzCzr5uZ2TB5roKvcaMENx4n6dfKHEUQw=; b=g6Iu1YblEUgB4H+zWH/m41gezlt1j6kQ7NpYrPyZQ/2GoWZDM/rHcm4sDDK7pPNCi6 dQpf7oAqLWpS9iuH/o7zm6NzCMgxUIxFU0w4fruliiKVYPZuFfXQET1YCOtFt6Keay1T aTnWL7BOj1Syg1ImkJRn1lLcQvChaJziw3A2ot4JnS005ZreQiwkSCttvgKNZr5E+jRb iVEwiZvyhq2esxnUxhxBxY7F+eOb992JxNULW4x1ebdGxieC8V7Urzjv2CkTcYi1H9pu /T5feAFQtZ9Sey2XR4i22TT42zgudvkktLJPgrPxE5GW4knK/W3RCfqK7v9PuXjiM7Ht QdPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=h7isTbtm; 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 a195si24054390pfd.143.2019.01.24.12.07.55; Thu, 24 Jan 2019 12:08:11 -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=h7isTbtm; 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 S1731327AbfAXUGf (ORCPT + 99 others); Thu, 24 Jan 2019 15:06:35 -0500 Received: from mail.kernel.org ([198.145.29.99]:58126 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730713AbfAXTac (ORCPT ); Thu, 24 Jan 2019 14:30:32 -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 AC971218D4; Thu, 24 Jan 2019 19:30:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548358232; bh=KsjOQH8H72TI0R+zeMSyBZis5f2UKu+RidECVnvbywI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h7isTbtmC04Zv5VM1HTmNqjJPETfdc6OrM04UNZttWiSewW9QAnG6s+HYA9LL0wJY IdQsVywzjlMEmk0Xj6NeU9LUrqFtMiOqkdf0WIWNEcL5KMR7dvKNXcbq4PqAIYzTKR +gD2/J6blRtDJhdljb1vGT0vbULiVOgb5GLjitdw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Adrian Hunter , Jiri Olsa , Namhyung Kim , Arjan van de Ven , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 4.9 26/39] perf svghelper: Fix unchecked usage of strncpy() Date: Thu, 24 Jan 2019 20:20:29 +0100 Message-Id: <20190124190449.187006218@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190124190448.232316246@linuxfoundation.org> References: <20190124190448.232316246@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.9-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 2f5302533f306d5ee87bd375aef9ca35b91762cb ] The strncpy() function may leave the destination string buffer unterminated, better use strlcpy() that we have a __weak fallback implementation for systems without it. In this specific case this would only happen if fgets() was buggy, as its man page states that it should read one less byte than the size of the destination buffer, so that it can put the nul byte at the end of it, so it would never copy 255 non-nul chars, as fgets reads into the orig buffer at most 254 non-nul chars and terminates it. But lets just switch to strlcpy to keep the original intent and silence the gcc 8.2 warning. This fixes this warning on an Alpine Linux Edge system with gcc 8.2: In function 'cpu_model', inlined from 'svg_cpu_box' at util/svghelper.c:378:2: util/svghelper.c:337:5: error: 'strncpy' output may be truncated copying 255 bytes from a string of length 255 [-Werror=stringop-truncation] strncpy(cpu_m, &buf[13], 255); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Cc: Adrian Hunter Cc: Jiri Olsa Cc: Namhyung Kim Cc: Arjan van de Ven Fixes: f48d55ce7871 ("perf: Add a SVG helper library file") Link: https://lkml.kernel.org/n/tip-xzkoo0gyr56gej39ltivuh9g@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/util/svghelper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/util/svghelper.c b/tools/perf/util/svghelper.c index 1cbada2dc6be..f735ee038713 100644 --- a/tools/perf/util/svghelper.c +++ b/tools/perf/util/svghelper.c @@ -334,7 +334,7 @@ static char *cpu_model(void) if (file) { while (fgets(buf, 255, file)) { if (strstr(buf, "model name")) { - strncpy(cpu_m, &buf[13], 255); + strlcpy(cpu_m, &buf[13], 255); break; } } -- 2.19.1