Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2366007imu; Thu, 24 Jan 2019 11:29:06 -0800 (PST) X-Google-Smtp-Source: ALg8bN6Sz3f/iesdt4yXpjwtQcS1boiYHDZvRQBF2Iodw3f9I7blTnCMnnO6zY2uy4qRlVat+3Bp X-Received: by 2002:a63:fc49:: with SMTP id r9mr6976591pgk.209.1548358145995; Thu, 24 Jan 2019 11:29:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548358145; cv=none; d=google.com; s=arc-20160816; b=oX04+jY6uRZC849kUZltopDHpTQTgaacVUzAzQaNn5vSsUoeTQ07vEL2Dhqb8AZQcW wUPqfAwyEs7PKFpAml5ICprWJ4Lp6wwNE5XVdVLO9lIm4fnDeKHaV2TwweLvy6JE9cbG 7jScN1N47ccDJeXgB91n5jKV27nHErffje6hGFisoWIC6Phzb+fbAkaRveg9ZyFWZfRW 0j1L8uvKpgHMYB+QzUlNFPN+GRO9mNyRPWGbStXw3zfpVJMKWzeBiDs/UMDrt1EWe0ll 76Z+oAb9fslXCyeWDjGiZatSyZNGf4JhPWgznshYpsRzUab76xG3zK/Xolj0a1fz1dUF 3JkQ== 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=9zxPTQ+RD6yoSPiVUvBVewCMwhOOgmQwG8HbmxEzHFU=; b=gjb/X5FyQorUGg5VXkwEkFAMe2E1k1Vyh0fOnR6PKbJqs7owrymIS+RQ2H3nK91VKt a8+NlQoG1hY5nsKE/ElrTi5nkNn6hSJaOP/ZjGtXsee4eA0wVIciigyKiKa+eV//WtiY yenRPy9MPBH8HtxM71H1moRRTFd5ZfddVNvXyCkA0HuYlh8mh9OTgTGdW/T+U0Zxa3OE qnmyP1R3Z8J/yjEa1vIiuY4Zt6i5lMqgbxbX/Ru+AN9m0RKxcw2LnwWLWk6XvYHG/c85 Uuq6pz2qYG4KCgRuqujZLZihRni+PyNkIdXxvK281Pl6WaT5iLnKdm6ngpLgUcV23Tp1 wcvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=DAvQop+A; 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 c26si22663325pgm.210.2019.01.24.11.28.50; Thu, 24 Jan 2019 11:29:05 -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=DAvQop+A; 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 S1730875AbfAXT2G (ORCPT + 99 others); Thu, 24 Jan 2019 14:28:06 -0500 Received: from mail.kernel.org ([198.145.29.99]:54482 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730857AbfAXT2E (ORCPT ); Thu, 24 Jan 2019 14:28:04 -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 6BE1A218A6; Thu, 24 Jan 2019 19:28:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548358083; bh=XWzUfeK1Nxtd2B/qln4OJuaQ92Qx+hiWAD7721rh1GY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DAvQop+AFOz39RE+ShwQpXKqOB3ffzGQUR9JvJsJFna2ny3cfxLQZUm3/EdQwWqIa waoDOUcqz9dA+pLRjC8HTALHNVpXSz+fh9XQdNiYGvSxuP2vMbhXkQffvlx3ahdLcb 0pG2shRsxPx3ReI3l6Rasl6i5SET9oPBiV7ufTEk= 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.4 093/104] perf svghelper: Fix unchecked usage of strncpy() Date: Thu, 24 Jan 2019 20:20:22 +0100 Message-Id: <20190124190205.098528798@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190124190154.968308875@linuxfoundation.org> References: <20190124190154.968308875@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.4-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 eec6c1149f44..132878d4847a 100644 --- a/tools/perf/util/svghelper.c +++ b/tools/perf/util/svghelper.c @@ -333,7 +333,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