Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3701368imu; Mon, 28 Jan 2019 09:16:42 -0800 (PST) X-Google-Smtp-Source: ALg8bN6AAb0Hnq0ACpbQsBSvdIZAi2XlyIav7i+BotE7NIIK/NjBlj/bXYi+Lr5cbSo5Oohes5xf X-Received: by 2002:a65:5387:: with SMTP id x7mr20625114pgq.412.1548695802837; Mon, 28 Jan 2019 09:16:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548695802; cv=none; d=google.com; s=arc-20160816; b=oIAnJitfJ6mafaPRzW3Nsj8aUM1R0+S4O9w7KOWnqPuXLQwpoBlQARGQ0+MH+ztDxy m4DiZ3r6v73OKWegZJKmu7K8eDvlwxArxgA/R5bQSfHAAPQVRPh7io8pqc+od/uOABb9 wtlB4fWm7PigBjOYFFT7bh933DpPRMhz6cfdVDBiU+58qo8cIduDzqhv7D+0tcpIQyXT 9+Py6ycLSaToVWH2rveX6bpcXV9Fuvz1mfpcH8mmuRsCfhLVqhQ2dIDXpt2F98QZ4Vcj JcKsjxN9EQq6tVUNEx0n2vBLCacsUXqQCvwCZRzHnMKZfi6E8voe+llLviYNoOctyUIl ECzA== 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=ie14YJQya1tJ/MbsWyAs8LVD6DHw2AOLfeE9EpuIIMk=; b=QC7E3+K8gPWOL4WYgSXoMnXPm28fXY2UmCeWgV25fsuuGso3eoDd/8D17VSIBCANk5 P5KOqnfcglHXiBvzypw2mfJOuko7QUAWJF8W+9EuluB869W7sge4G4D0Ohfhfr23geg0 Nl9M6oKK5mD2rycjIk94XEG/OD2+CCPriQGe7eAAH03QyquqbJrfsC+WZdeLawfgmA7r RI+VVvzo2V/Za6vRO9SmgAIbk1bKUo2LmsZaI2EplOTZcpIeb3z6VEbUcUGg4+aZLHgS m5oTVCan5xUkzBwDyFYRrsRoFebH8J2shvhtAlglm/4fifrvq4dvHC8nizH3k8NTnBNR oB6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=x4QI8K6m; 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 a5si4782457pgg.120.2019.01.28.09.16.27; Mon, 28 Jan 2019 09:16:42 -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=x4QI8K6m; 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 S1732129AbfA1RPG (ORCPT + 99 others); Mon, 28 Jan 2019 12:15:06 -0500 Received: from mail.kernel.org ([198.145.29.99]:57910 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732180AbfA1QHW (ORCPT ); Mon, 28 Jan 2019 11:07:22 -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 E38C721738; Mon, 28 Jan 2019 16:07:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548691641; bh=ZfOzqy/RpatpUbgK71wD2CIOY2K0yjUR89SK3aMXodU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=x4QI8K6mweI4kBYMQcnb78Pq4cb1PIJ9Z+jHbKX1X0dw2VQEh1jgpfFK3v23pKOLo ya4G3zB/tFhYTOUnitfbtDM1THIYtNycZQBpeQqSYXybouZJwnzCpyQJHrydHXGtwA 0LMdV2NnphTCvJyp4hJkIdnTAZS/AH3XtFR5ZXFk= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Arnaldo Carvalho de Melo , Adrian Hunter , Jiri Olsa , Masami Hiramatsu , Namhyung Kim , Sasha Levin Subject: [PATCH AUTOSEL 4.19 169/258] perf probe: Fix unchecked usage of strncpy() Date: Mon, 28 Jan 2019 10:57:55 -0500 Message-Id: <20190128155924.51521-169-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 bef0b8970f27da5ca223e522a174d03e2587761d ] 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 case the 'target' buffer is coming from a list of build-ids that are expected to have a len of at most (SBUILD_ID_SIZE - 1) chars, so probably we're safe, but since we're using strncpy() here, use strlcpy() instead to provide the intended safety checking without the using the problematic strncpy() function. This fixes this warning on an Alpine Linux Edge system with gcc 8.2: util/probe-file.c: In function 'probe_cache__open.isra.5': util/probe-file.c:427:3: error: 'strncpy' specified bound 41 equals destination size [-Werror=stringop-truncation] strncpy(sbuildid, target, SBUILD_ID_SIZE); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors Cc: Adrian Hunter Cc: Jiri Olsa Cc: Masami Hiramatsu Cc: Namhyung Kim Fixes: 1f3736c9c833 ("perf probe: Show all cached probes") Link: https://lkml.kernel.org/n/tip-l7n8ggc9kl38qtdlouke5yp5@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/util/probe-file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c index b76088fadf3d..6a6548890d5a 100644 --- a/tools/perf/util/probe-file.c +++ b/tools/perf/util/probe-file.c @@ -424,7 +424,7 @@ static int probe_cache__open(struct probe_cache *pcache, const char *target, if (target && build_id_cache__cached(target)) { /* This is a cached buildid */ - strncpy(sbuildid, target, SBUILD_ID_SIZE); + strlcpy(sbuildid, target, SBUILD_ID_SIZE); dir_name = build_id_cache__linkname(sbuildid, NULL, 0); goto found; } -- 2.19.1