Skip to contentSkip to conversation

Small trace-cmd fixes

PATCH New Tzvetomir Stoyanov (VMware) 1 participant 3 messages Apr 9, 2020

lore
Share & tools
lore
#0 lore raw

cover Small trace-cmd fixes

Small fixes, good to have in the next trace-cmd release.

Tzvetomir Stoyanov (VMware) (2):
trace-cmd: Fix possible usage of not null-terminated string
trace-cmd: Fix reading of the traceid option from trace.dat file

 lib/trace-cmd/trace-input.c  | 4 +++-
 lib/trace-cmd/trace-plugin.c | 1 +
 lib/trace-cmd/trace-util.c   | 1 +
 3 files changed, 5 insertions(+), 1 deletion(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/2 trace-cmd: Fix possible usage of not null-terminated string

According to the
readlink(const char *filename, char *buffer, size_t size);
documentation, the terminating '\0' is not written in the buffer. As the buffer that is passed to this API is not initialized, this can lead to working with not null-terminated string. The problem was detected by valgrind.

---
 lib/trace-cmd/trace-plugin.c | 1 +
 lib/trace-cmd/trace-util.c   | 1 +
 2 files changed, 2 insertions(+)
lib/trace-cmd/trace-plugin.c +1 -0
index 6bec18bc..92f9edf3 100644
@@ -199,6 +199,7 @@ static char *get_source_plugins_dir(void)
 	if (ret > PATH_MAX || ret < 0)
 		return NULL;
 
+	path[ret] = 0;
 	dirname(path);
 	p = strrchr(path, '/');
 	if (!p)
lib/trace-cmd/trace-util.c +1 -0
index 04dc804c..0ead96ea 100644
@@ -269,6 +269,7 @@ static char *get_source_plugins_dir(void)
 	if (ret > PATH_MAX || ret < 0)
 		return NULL;
 
+	path[ret] = 0;
 	dirname(path);
 	p = strrchr(path, '/');
 	if (!p)
Signature · 1 line
2.25.1
#2 lore raw

PATCH 2/2 trace-cmd: Fix reading of the traceid option from trace.dat file

In reply to Tzvetomir Stoyanov (VMware)

Due to a copy / paste error, the reading of traceid option from trace.dat file is broken. There is no impact to the user, as this option is not used yet.

---
 lib/trace-cmd/trace-input.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/trace-cmd/trace-input.c +3 -1
index c1531410..f04528ae 100644
@@ -2554,8 +2554,10 @@ static int handle_options(struct tracecmd_input *handle)
 				trace_pid_map_load(handle, buf);
 			break;
 		case TRACECMD_OPTION_TRACEID:
+			if (size != 8)
+				break;
 			handle->trace_id = tep_read_number(handle->pevent,
-							   &cpus, 8);
+							   buf, 8);
 			break;
 		case TRACECMD_OPTION_GUEST:
 			trace_guest_load(handle, buf, size);
Signature · 1 line
2.25.1