[<prev] [next>] [day] [month] [year] [list]
Message-Id: <1401918470-3947-1-git-send-email-rickard_strandqvist@spectrumdigital.se>
Date: Wed, 4 Jun 2014 23:47:50 +0200
From: Rickard Strandqvist <rickard_strandqvist@...ctrumdigital.se>
To: Peter Zijlstra <a.p.zijlstra@...llo.nl>,
Paul Mackerras <paulus@...ba.org>
Cc: Rickard Strandqvist <rickard_strandqvist@...ctrumdigital.se>,
Ingo Molnar <mingo@...hat.com>,
Arnaldo Carvalho de Melo <acme@...nel.org>,
Stanislav Fomichev <stfomichev@...dex-team.ru>,
Namhyung Kim <namhyung@...nel.org>,
linux-kernel@...r.kernel.org
Subject: [PATCH] tools: perf: util: svghelper.c: Cleaning up missing null-terminate after strncpy call
Added a guaranteed null-terminate after call to strncpy.
This was partly found using a static code analysis program called cppcheck.
Signed-off-by: Rickard Strandqvist <rickard_strandqvist@...ctrumdigital.se>
---
tools/perf/util/svghelper.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/tools/perf/util/svghelper.c b/tools/perf/util/svghelper.c
index 43262b8..cdcb332 100644
--- a/tools/perf/util/svghelper.c
+++ b/tools/perf/util/svghelper.c
@@ -255,9 +255,10 @@ static char *cpu_model(void)
/* CPU type */
file = fopen("/proc/cpuinfo", "r");
if (file) {
- while (fgets(buf, 255, file)) {
+ while (fgets(buf, sizeof(buf), file)) {
if (strstr(buf, "model name")) {
- strncpy(cpu_m, &buf[13], 255);
+ strncpy(cpu_m, &buf[13], sizeof(cpu_m));
+ cpu_m[sizeof(cpu_m) - 1] = '\0';
break;
}
}
@@ -267,7 +268,7 @@ static char *cpu_model(void)
/* CPU type */
file = fopen("/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies", "r");
if (file) {
- while (fgets(buf, 255, file)) {
+ while (fgets(buf, sizeof(buf), file)) {
unsigned int freq;
freq = strtoull(buf, NULL, 10);
if (freq > max_freq)
--
1.7.10.4
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists