Skip to contentSkip to conversation

Fix unterminated buffer if the length of str exceeds MAX_TRACER_SIZE

PATCH New Thomas Jarosch 1 participant 1 message Oct 16, 2011 Tracing

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix unterminated buffer if the length of str exceeds MAX_TRACER_SIZE

strncpy() doesn't always zero terminate the string.

Detected by "cppcheck"

---
 kernel/trace/trace.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
kernel/trace/trace.c +2 -1
index e5df02c..9637b1e 100644
@@ -126,7 +126,8 @@ static char *default_bootup_tracer;
 
 static int __init set_cmdline_ftrace(char *str)
 {
-	strncpy(bootup_tracer_buf, str, MAX_TRACER_SIZE);
+	strncpy(bootup_tracer_buf, str, MAX_TRACER_SIZE-1);
+	bootup_tracer_buf[MAX_TRACER_SIZE-1] = '\0';
 	default_bootup_tracer = bootup_tracer_buf;
 	/* We are using ftrace early, expand it */
 	ring_buffer_expanded = 1;
Signature · 1 line
1.7.6.4