* [PATCH] trace-cmd split: Fix creation of temp files to include output name
@ 2023-07-10 16:50 Steven Rostedt
0 siblings, 0 replies; only message in thread
From: Steven Rostedt @ 2023-07-10 16:50 UTC (permalink / raw)
To: Linux Trace Devel; +Cc: Sharon Gabay
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
The creation of the temp files for creating the split did the following:
output = strdup(output_file);
dir = dirname(output);
base = basename(output);
The problem with the above is that dirname() modifies "output" to add a
'\0' after the directory name. That is, if we had output_file = '/tmp/test';
Then the following will happen:
output = copy of "/tmp/test"
dir = dirname(output);
This will set dir to "/tmp" and insert a '\0' into the second '/'. This
also has the side effect of changing output to "/tmp" as well.
Then to get the base name:
base = basename(output);
base will end up as "tmp" and not as "test". The temp file will then be:
ret = asprintf(&file, "%s/.tmp.%s.%d", dir, base, cpu);
"/tmp/.tmp.tmp.1"
This is incorrect, as it should have been "/tmp/.tmp.test.1".
This can easily be fixed by swapping the assignment of dir and base:
base = basename(output);
dir = dirname(output);
As then, after the assignment of base, base would be "test" and output
would still be "/tmp/test", allowing for dir to get "/tmp".
Link: https://lore.kernel.org/linux-trace-users/VE1PR09MB3535122A0DA44242886307B9F233A@VE1PR09MB3535.eurprd09.prod.outlook.com/
Reported-by: Sharon Gabay <Sharon.Gabay@mobileye.com>
Fixes: d9b58d42c43c2 ("trace-cmd: Fix temp files in trace-cmd split to include directories")
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
tracecmd/trace-split.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tracecmd/trace-split.c b/tracecmd/trace-split.c
index 59df1d02b345..4fda781307e6 100644
--- a/tracecmd/trace-split.c
+++ b/tracecmd/trace-split.c
@@ -367,8 +367,9 @@ static double parse_file(struct tracecmd_input *handle,
int fd;
output = strdup(output_file);
- dir = dirname(output);
+ /* Extract basename() first, as dirname() truncates output */
base = basename(output);
+ dir = dirname(output);
ohandle = tracecmd_copy(handle, output_file, TRACECMD_FILE_CMD_LINES, 0, NULL);
--
2.39.2
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2023-07-10 16:50 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-10 16:50 [PATCH] trace-cmd split: Fix creation of temp files to include output name Steven Rostedt
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).