From: Chase Douglas <chase.douglas@canonical.com>
To: Steven Rostedt <srostedt@redhat.com>
Cc: Valdis.Kletnieks@vt.edu, Frederic Weisbecker <fweisbec@gmail.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH v2] trace-cmd: prevent print_graph_duration buffer overflow
Date: Tue, 15 Jun 2010 10:47:04 -0400 [thread overview]
Message-ID: <1276613224-19247-1-git-send-email-chase.douglas@canonical.com> (raw)
Passing n > sizeof(string) to snprintf can cause a glibc buffer overflow
condition. We know the exact size of nsecs_str, so use it along with the
the math to determine the longest string size we want.
Note that an overflow isn't really possible given the format of the
string. However, glibc would abort due to a runtime check.
Signed-off-by: Chase Douglas <chase.douglas@canonical.com>
---
trace-ftrace.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/trace-ftrace.c b/trace-ftrace.c
index af9ac8d..181a00f 100644
--- a/trace-ftrace.c
+++ b/trace-ftrace.c
@@ -21,6 +21,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/param.h>
#include "trace-cmd.h"
@@ -148,7 +149,7 @@ static void print_graph_duration(struct trace_seq *s, unsigned long long duratio
/* Print nsecs (we don't want to exceed 7 numbers) */
if ((s->len - len) < 7) {
- snprintf(nsecs_str, 8 - (s->len - len), "%03lu", nsecs_rem);
+ snprintf(nsecs_str, MIN(sizeof(nsecs_str), 8 - len), "%03lu", nsecs_rem);
trace_seq_printf(s, ".%s", nsecs_str);
}
--
1.7.0.4
next reply other threads:[~2010-06-15 14:47 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-15 14:47 Chase Douglas [this message]
2010-06-15 14:54 ` Steven Rostedt
2010-06-15 15:21 ` Chase Douglas
2010-06-15 15:38 ` Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1276613224-19247-1-git-send-email-chase.douglas@canonical.com \
--to=chase.douglas@canonical.com \
--cc=Valdis.Kletnieks@vt.edu \
--cc=fweisbec@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=srostedt@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®