Skip to contentSkip to conversation

trace-cmd: Fix possible usage of not null-terminated string

PATCH New Tzvetomir Stoyanov (VMware) 1 participant 1 message Apr 2, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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