linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] Small trace-cmd fixes
@ 2020-04-09 13:27 Tzvetomir Stoyanov (VMware)
  2020-04-09 13:27 ` [PATCH 1/2] trace-cmd: Fix possible usage of not null-terminated string Tzvetomir Stoyanov (VMware)
  2020-04-09 13:27 ` [PATCH 2/2] trace-cmd: Fix reading of the traceid option from trace.dat file Tzvetomir Stoyanov (VMware)
  0 siblings, 2 replies; 3+ messages in thread
From: Tzvetomir Stoyanov (VMware) @ 2020-04-09 13:27 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel

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(-)

-- 
2.25.1


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

* [PATCH 1/2] trace-cmd: Fix possible usage of not null-terminated string
  2020-04-09 13:27 [PATCH 0/2] Small trace-cmd fixes Tzvetomir Stoyanov (VMware)
@ 2020-04-09 13:27 ` Tzvetomir Stoyanov (VMware)
  2020-04-09 13:27 ` [PATCH 2/2] trace-cmd: Fix reading of the traceid option from trace.dat file Tzvetomir Stoyanov (VMware)
  1 sibling, 0 replies; 3+ messages in thread
From: Tzvetomir Stoyanov (VMware) @ 2020-04-09 13:27 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel

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.

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

diff --git a/lib/trace-cmd/trace-plugin.c b/lib/trace-cmd/trace-plugin.c
index 6bec18bc..92f9edf3 100644
--- a/lib/trace-cmd/trace-plugin.c
+++ b/lib/trace-cmd/trace-plugin.c
@@ -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)
diff --git a/lib/trace-cmd/trace-util.c b/lib/trace-cmd/trace-util.c
index 04dc804c..0ead96ea 100644
--- a/lib/trace-cmd/trace-util.c
+++ b/lib/trace-cmd/trace-util.c
@@ -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)
-- 
2.25.1


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

* [PATCH 2/2] trace-cmd: Fix reading of the traceid option from trace.dat file
  2020-04-09 13:27 [PATCH 0/2] Small trace-cmd fixes Tzvetomir Stoyanov (VMware)
  2020-04-09 13:27 ` [PATCH 1/2] trace-cmd: Fix possible usage of not null-terminated string Tzvetomir Stoyanov (VMware)
@ 2020-04-09 13:27 ` Tzvetomir Stoyanov (VMware)
  1 sibling, 0 replies; 3+ messages in thread
From: Tzvetomir Stoyanov (VMware) @ 2020-04-09 13:27 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel

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.

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

diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c
index c1531410..f04528ae 100644
--- a/lib/trace-cmd/trace-input.c
+++ b/lib/trace-cmd/trace-input.c
@@ -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);
-- 
2.25.1


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

end of thread, other threads:[~2020-04-09 13:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-09 13:27 [PATCH 0/2] Small trace-cmd fixes Tzvetomir Stoyanov (VMware)
2020-04-09 13:27 ` [PATCH 1/2] trace-cmd: Fix possible usage of not null-terminated string Tzvetomir Stoyanov (VMware)
2020-04-09 13:27 ` [PATCH 2/2] trace-cmd: Fix reading of the traceid option from trace.dat file Tzvetomir Stoyanov (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).