From e5490da918186cbd42b8609da146946fbdadf0e5 Mon Sep 17 00:00:00 2001
From: William Cohen <wcohen@redhat.com>
Date: Thu, 2 Feb 2017 12:02:51 -0500
Subject: [PATCH] Avoid hypthetical string truncation in various oprofile
buffers
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Increased the size of internal oprofile driver buffers ensuring that
the strings were never truncated for any possible values to avoid
warning/errors like the following GCC 7 compiler error on ppc when
building the kernel:
linux/arch/powerpc/oprofile/../../../drivers/oprofile/oprofile_stats.c: In function ‘oprofile_create_stats_files’:
linux/arch/powerpc/oprofile/../../../drivers/oprofile/oprofile_stats.c:55:25: error: ‘%d’ directive output may be truncated writing between 1 and 11 bytes into a region of size 7 [-Werror=format-truncation=]
snprintf(buf, 10, "cpu%d", i);
^~
linux/arch/powerpc/oprofile/../../../drivers/oprofile/oprofile_stats.c:55:21: note: using the range [1, -2147483648] for directive argument
snprintf(buf, 10, "cpu%d", i);
^~~~~~~
linux/arch/powerpc/oprofile/../../../drivers/oprofile/oprofile_stats.c:55:3: note: format output between 5 and 15 bytes into a destination of size 10
snprintf(buf, 10, "cpu%d", i);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
LD crypto/async_tx/built-in.o
CC lib/random32.o
cc1: all warnings being treated as errors
Signed-off-by: William Cohen <wcohen@redhat.com>
---
arch/alpha/oprofile/common.c | 4 ++--
arch/avr32/oprofile/op_model_avr32.c | 2 +-
arch/mips/oprofile/common.c | 4 ++--
arch/powerpc/oprofile/common.c | 4 ++--
arch/x86/oprofile/nmi_int.c | 2 +-
drivers/oprofile/oprofile_perf.c | 4 ++--
drivers/oprofile/oprofile_stats.c | 4 ++--
7 files changed, 12 insertions(+), 12 deletions(-)
@@ -112,9 +112,9 @@ op_axp_create_files(struct dentry *root)
for (i = 0; i < model->num_counters; ++i) {
struct dentry *dir;
- char buf[4];
+ char buf[32];
- snprintf(buf, sizeof buf, "%d", i);
+ snprintf(buf, sizeof(buf), "%d", i);
dir = oprofilefs_mkdir(root, buf);
oprofilefs_create_ulong(dir, "enabled", &ctr[i].enabled);
@@ -101,7 +101,7 @@ static int avr32_perf_counter_create_files(struct dentry *root)
{
struct dentry *dir;
unsigned int i;
- char filename[4];
+ char filename[32];
for (i = 0; i < NR_counter; i++) {
snprintf(filename, sizeof(filename), "%u", i);
@@ -41,9 +41,9 @@ static int op_mips_create_files(struct dentry *root)
for (i = 0; i < model->num_counters; ++i) {
struct dentry *dir;
- char buf[4];
+ char buf[32];
- snprintf(buf, sizeof buf, "%d", i);
+ snprintf(buf, sizeof(buf), "%d", i);
dir = oprofilefs_mkdir(root, buf);
oprofilefs_create_ulong(dir, "enabled", &ctr[i].enabled);
@@ -157,9 +157,9 @@ static int op_powerpc_create_files(struct dentry *root)
for (i = 0; i < model->num_counters; ++i) {
struct dentry *dir;
- char buf[4];
+ char buf[32];
- snprintf(buf, sizeof buf, "%d", i);
+ snprintf(buf, sizeof(buf), "%d", i);
dir = oprofilefs_mkdir(root, buf);
oprofilefs_create_ulong(dir, "enabled", &ctr[i].enabled);
@@ -416,7 +416,7 @@ static int nmi_create_files(struct dentry *root)
for (i = 0; i < model->num_virt_counters; ++i) {
struct dentry *dir;
- char buf[4];
+ char buf[32];
/* quick little hack to _not_ expose a counter if it is not
* available for use. This should protect userspace app.
@@ -144,9 +144,9 @@ static int oprofile_perf_create_files(struct dentry *root)
for (i = 0; i < num_counters; i++) {
struct dentry *dir;
- char buf[4];
+ char buf[32];
- snprintf(buf, sizeof buf, "%d", i);
+ snprintf(buf, sizeof(buf), "%d", i);
dir = oprofilefs_mkdir(root, buf);
oprofilefs_create_ulong(dir, "enabled", &counter_config[i].enabled);
oprofilefs_create_ulong(dir, "event", &counter_config[i].event);
@@ -43,7 +43,7 @@ void oprofile_create_stats_files(struct dentry *root)
struct oprofile_cpu_buffer *cpu_buf;
struct dentry *cpudir;
struct dentry *dir;
- char buf[10];
+ char buf[32];
int i;
dir = oprofilefs_mkdir(root, "stats");
@@ -52,7 +52,7 @@ void oprofile_create_stats_files(struct dentry *root)
for_each_possible_cpu(i) {
cpu_buf = &per_cpu(op_cpu_buffer, i);
- snprintf(buf, 10, "cpu%d", i);
+ snprintf(buf, sizeof(buf), "cpu%d", i);
cpudir = oprofilefs_mkdir(dir, buf);
/* Strictly speaking access to these ulongs is racy,
--
2.9.3