[trace PATCH] Fix unterminated buffer if the length of str exceedsMAX_TRACER_SIZE

From: Thomas Jarosch
Date: Sun Oct 16 2011 - 05:39:14 EST


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

Detected by "cppcheck"

Signed-off-by: Thomas Jarosch <thomas.jarosch@xxxxxxxxxxxxx>
---
kernel/trace/trace.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index e5df02c..9637b1e 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -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;
--
1.7.6.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/