linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org
Subject: [PATCH 2/3] libtracefs: Fix loading of saved maps
Date: Mon, 12 Apr 2021 07:24:18 +0300	[thread overview]
Message-ID: <20210412042419.3295237-3-tz.stoyanov@gmail.com> (raw)
In-Reply-To: <20210412042419.3295237-1-tz.stoyanov@gmail.com>

The internal helper function, used for loading saved printk formats,
kallsyms and command lines retuns 0 in case the given file exist,
but is empty. In that case a buffer is not allocated and size 0 is
returned. Logic for loading those mappings does not handle that case,
which leads to memory corrupion freeing invalid memory.

Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
 src/tracefs-events.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/tracefs-events.c b/src/tracefs-events.c
index 94573b3..3a6196b 100644
--- a/src/tracefs-events.c
+++ b/src/tracefs-events.c
@@ -603,7 +603,7 @@ static void load_kallsyms(struct tep_handle *tep)
 {
 	char *buf;
 
-	if (str_read_file("/proc/kallsyms", &buf, false) < 0)
+	if (str_read_file("/proc/kallsyms", &buf, false) <= 0)
 		return;
 
 	tep_parse_kallsyms(tep, buf);
@@ -623,7 +623,7 @@ static int load_saved_cmdlines(const char *tracing_dir,
 
 	ret = str_read_file(path, &buf, false);
 	free(path);
-	if (ret < 0)
+	if (ret <= 0)
 		return -1;
 
 	ret = tep_parse_saved_cmdlines(tep, buf);
@@ -645,7 +645,7 @@ static void load_printk_formats(const char *tracing_dir,
 
 	ret = str_read_file(path, &buf, false);
 	free(path);
-	if (ret < 0)
+	if (ret <= 0)
 		return;
 
 	tep_parse_printk_formats(tep, buf);
-- 
2.30.2


  parent reply	other threads:[~2021-04-12  4:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-12  4:24 [PATCH 0/3] Fix unit tests and APIs for loading saved mappings Tzvetomir Stoyanov (VMware)
2021-04-12  4:24 ` [PATCH 1/3] libtracefs: Fix trace options unit test Tzvetomir Stoyanov (VMware)
2021-04-12  4:24 ` Tzvetomir Stoyanov (VMware) [this message]
2021-04-12  4:24 ` [PATCH 3/3] libtracefs: Fixed trace marker " Tzvetomir Stoyanov (VMware)

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=20210412042419.3295237-3-tz.stoyanov@gmail.com \
    --to=tz.stoyanov@gmail.com \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=rostedt@goodmis.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).