From: Steven Rostedt <rostedt@goodmis.org>
To: Linux Trace Devel <linux-trace-devel@vger.kernel.org>
Subject: [PATCH] tracefs utils: Do not free a the buffer on a zero size str_read_file()
Date: Mon, 23 Nov 2020 15:34:47 -0500 [thread overview]
Message-ID: <20201123153447.2e24c678@gandalf.local.home> (raw)
From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
If a file has no size (nothing is read), then str_read_file() frees the
buffer and returns zero. The problem is that all callers of str_read_file()
uses the buffer supplied if the value returned is not a negative. This
causes the freed buffer being used by the callers if the file read existed
but had no content.
This is apparent when using a copy of the tracefs directory, where some file
exist, but have no content, then loading the events would cause a segfault.
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
tracefs-utils.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tracefs-utils.c b/tracefs-utils.c
index 326b455..690506c 100644
--- a/tracefs-utils.c
+++ b/tracefs-utils.c
@@ -220,7 +220,7 @@ __hidden int str_read_file(const char *file, char **buffer)
} while (r > 0);
close(fd);
- if (r == 0 && size > 0) {
+ if (r == 0) {
buf[size] = '\0';
*buffer = buf;
} else
--
2.25.4
next reply other threads:[~2020-11-23 20:34 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-23 20:34 Steven Rostedt [this message]
2020-11-24 5:44 ` [PATCH] tracefs utils: Do not free a the buffer on a zero size str_read_file() Tzvetomir Stoyanov
2020-11-24 13:52 ` Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201123153447.2e24c678@gandalf.local.home \
--to=rostedt@goodmis.org \
--cc=linux-trace-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).