Skip to contentSkip to conversation

tools/lib/traceevent: fix a buffer overrun

PATCH New Tzvetomir Stoyanov 1 participant 1 message Jan 25, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/lib/traceevent: fix a buffer overrun

Fix a buffer overrun in arg_eval() function in traceevent library. The min value of long long is -9223372036854775808, it needs at least 21 bytes to be printed as a string.

---
 tools/lib/traceevent/event-parse.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/lib/traceevent/event-parse.c +2 -2
index f6c926467fa3..ff065796ace3 100644
@@ -2472,7 +2472,7 @@ static int arg_num_eval(struct tep_print_arg *arg, long long *val)
 static char *arg_eval (struct tep_print_arg *arg)
 {
 	long long val;
-	static char buf[20];
+	static char buf[21];
 
 	switch (arg->type) {
 	case TEP_PRINT_ATOM:
@@ -2482,7 +2482,7 @@ static char *arg_eval (struct tep_print_arg *arg)
 	case TEP_PRINT_OP:
 		if (!arg_num_eval(arg, &val))
 			break;
-		sprintf(buf, "%lld", val);
+		snprintf(buf, 21, "%lld", val);
 		return buf;
 
 	case TEP_PRINT_NULL:
Signature · 1 line
2.20.1