linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] trace-cmd: Fixed a potential problem with non-terminated string, returned by readlink()
@ 2019-07-03 12:16 tz.stoyanov
  2019-07-04 12:39 ` Yordan Karadzhov (VMware)
  0 siblings, 1 reply; 2+ messages in thread
From: tz.stoyanov @ 2019-07-03 12:16 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel

From: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>

The buffer, returned by readlink() API, is not guaranteed to be a null terminated string.
Explicitly adding '\0' at the end of the buffer is recommended, to ensure the string is
null terminated and to avoid possible buffer overruns.

Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
 lib/trace-cmd/trace-util.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lib/trace-cmd/trace-util.c b/lib/trace-cmd/trace-util.c
index 190cf74..7c74bae 100644
--- a/lib/trace-cmd/trace-util.c
+++ b/lib/trace-cmd/trace-util.c
@@ -1373,6 +1373,7 @@ static char *trace_util_get_source_plugins_dir(void)
 	ret = readlink("/proc/self/exe", path, PATH_MAX);
 	if (ret > PATH_MAX || ret < 0)
 		return NULL;
+	path[ret] = 0;
 
 	dirname(path);
 	p = strrchr(path, '/');
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-07-04 12:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-03 12:16 [PATCH] trace-cmd: Fixed a potential problem with non-terminated string, returned by readlink() tz.stoyanov
2019-07-04 12:39 ` Yordan Karadzhov (VMware)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).