Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5131618imu; Tue, 8 Jan 2019 12:05:45 -0800 (PST) X-Google-Smtp-Source: ALg8bN6Iw3pHh99qiIQBwS3s2kXATNAJeOE8GQiUzmVwcPJYCfzHkBIZsaVHIjROw1KafG+qy9N/ X-Received: by 2002:a63:b34f:: with SMTP id x15mr2760050pgt.243.1546977945354; Tue, 08 Jan 2019 12:05:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546977945; cv=none; d=google.com; s=arc-20160816; b=GEIjvu3vEw2KfHvECjxzkyToNUGmq70yvWXmaPHvGB+8Kc4I13pJ4TMo4emeN5hhvT B8lFDSUWixnMGSgUTQuZauAaVyIk+9vL8vwPUs1HvehiVQUXP5YnwgfE2FySiLIWR50C BECygr0wLkIBP97oH1XZ0exG5ITMFS32irCtH/6iE1If7mg6TuFWCxRnUplEbusVKw86 MQZt4c1uNKAcN6ZkzpwLUw6bBiPA2byui16EXM+JtxGRuNDsIcqCd4ECYWddLou1nqDF 0UmTsgK5WemaN3Z8fXKkZR0CHmvPgayLHnGptWyU440XX+wtO61SzRBnKKKEjRDjuukc SDNg== 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=Lh93VCmBfcV9FuzdfhLwHlfBiBm0lyXXHhXeFNokheM=; b=w1e7Fo/gcvkyti2fA8zveEdDKI+MNpvVExnVRfmb6SWBJIR+xPt9Ta4MibyIP359x6 baEtJTgmhEnk3gydwFLQi/VWedHpgIp13qC7mU+ar7yiiSVSAXQm4a0vvooMP0y/daVd NL6PrFPcH/GYE1RSx5M8fGnLtHoReHgaZcoQ70bfnU1jBqDDwYoWvM0eLBFb3pjjUTYL nTkXKqz6sLoRORRL2u0YgN45DixaXykwMfoAlctWXtAw2RHNrJT6jxb8n11BsL648kpI ADkIYkuwVkt0qeDx57qW6JLXEdQ0/8vvp1Q1mgXzZLmu9SuVUbxpVxDTK6Ge0QYrzL3D yKOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=q6hMqCcb; 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 t19si11422695pgu.5.2019.01.08.12.05.30; Tue, 08 Jan 2019 12:05:45 -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=q6hMqCcb; 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 S1730213AbfAHT2z (ORCPT + 99 others); Tue, 8 Jan 2019 14:28:55 -0500 Received: from mail.kernel.org ([198.145.29.99]:35976 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730168AbfAHT2u (ORCPT ); Tue, 8 Jan 2019 14:28:50 -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 8782520883; Tue, 8 Jan 2019 19:28:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1546975729; bh=gIEXv2DrrCFcuLBLc+cGlLVKNNeUhmCn+6HG2qvpy4c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q6hMqCcbfdy2uHf3E0xKl7ZUnJ6kqi3rzKw/5KOVUttEIfa1hwavYJkr6ySVxnx+C 4h14a0UrjxphdkL1Jd+jiYIBf9oZ7H9AxFru6KDuABCIYC9ZmEBb4ucg5I0KqqvmXf trH7Or+LZPRjxF9ci/toU2DQk6wTu13IjS1EugqA= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Arnaldo Carvalho de Melo , Adrian Hunter , Jiri Olsa , Namhyung Kim , Arjan van de Ven , Sasha Levin Subject: [PATCH AUTOSEL 4.20 081/117] perf svghelper: Fix unchecked usage of strncpy() Date: Tue, 8 Jan 2019 14:25:49 -0500 Message-Id: <20190108192628.121270-81-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190108192628.121270-1-sashal@kernel.org> References: <20190108192628.121270-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 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