From: Sean Anderson <seanga2@gmail.com>
To: linux-kernel@vger.kernel.org, Andrew Morton <akpm@linux-foundation.org>
Cc: Changhee Han <ch0.han@lge.com>,
Zhenliang Wei <weizhenliang@huawei.com>,
Zhang Shengju <zhangshengju@cmss.chinamobile.com>,
Tang Bin <tangbin@cmss.chinamobile.com>,
Sean Anderson <seanga2@gmail.com>
Subject: [PATCH] tools/vm/page_owner_sort.c: Fix NULL-pointer dereference when comparing stack traces
Date: Thu, 25 Nov 2021 11:26:53 -0500 [thread overview]
Message-ID: <20211125162653.1855958-1-seanga2@gmail.com> (raw)
If there is no newline in a block, then strchr returns NULL. We check for
this in stacktrace_compare, but not when culling. Fix this (and any future
bugs like it) by replacing NULL stack traces with "" in add_list.
Fixes: d0abbab9e9e9 ("tools/vm/page_owner_sort.c: sort by stacktrace before culling")
Signed-off-by: Sean Anderson <seanga2@gmail.com>
---
tools/vm/page_owner_sort.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/vm/page_owner_sort.c b/tools/vm/page_owner_sort.c
index b91d3381300c..1b2acf02d3cd 100644
--- a/tools/vm/page_owner_sort.c
+++ b/tools/vm/page_owner_sort.c
@@ -55,7 +55,7 @@ static int compare_stacktrace(const void *p1, const void *p2)
{
const struct block_list *l1 = p1, *l2 = p2;
- return strcmp(l1->stacktrace ?: "", l2->stacktrace ?: "");
+ return strcmp(l1->stacktrace, l2->stacktrace);
}
static int compare_num(const void *p1, const void *p2)
@@ -121,7 +121,7 @@ static void add_list(char *buf, int len)
list[list_size].page_num = get_page_num(buf);
memcpy(list[list_size].txt, buf, len);
list[list_size].txt[len] = 0;
- list[list_size].stacktrace = strchr(list[list_size].txt, '\n');
+ list[list_size].stacktrace = strchr(list[list_size].txt, '\n') ?: "";
list_size++;
if (list_size % 1000 == 0) {
printf("loaded %d\r", list_size);
--
2.33.0
reply other threads:[~2021-11-25 16:47 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20211125162653.1855958-1-seanga2@gmail.com \
--to=seanga2@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=ch0.han@lge.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tangbin@cmss.chinamobile.com \
--cc=weizhenliang@huawei.com \
--cc=zhangshengju@cmss.chinamobile.com \
/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
all inboxes | Powered by JetHome®