From 7e46dbd7dc5bc941926a4a63c28ccebf46493e8d Mon Sep 17 00:00:00 2001
From: William Cohen <wcohen@redhat.com>
Date: Thu, 26 Jan 2017 10:33:59 -0500
Subject: [PATCH] Avoid hypthetical string truncation in oprofile stats buffer
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Increased the size of an internal oprofile driver buffer ensuring that
the string was never truncated for any possible int value to avoid 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>
---
drivers/oprofile/oprofile_stats.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
@@ -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[16];
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, 16, "cpu%d", i);
cpudir = oprofilefs_mkdir(dir, buf);
/* Strictly speaking access to these ulongs is racy,
--
2.9.3