lkml.org 
[lkml]   [2022]   [Mar]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 2/3] tools/vm/page_owner_sort.c: add a security check
Date
Add a security check after using malloc() to allocate memory.

Signed-off-by: Jiajian Ye <yejiajian2018@email.szu.edu.cn>
---
tools/vm/page_owner_sort.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/tools/vm/page_owner_sort.c b/tools/vm/page_owner_sort.c
index 79d69c3b84ed..69fb6ca7c0b7 100644
--- a/tools/vm/page_owner_sort.c
+++ b/tools/vm/page_owner_sort.c
@@ -217,7 +217,13 @@ static void add_list(char *buf, int len)
printf("max_size too small??\n");
exit(1);
}
+
list[list_size].txt = malloc(len+1);
+ if (!list[list_size].txt) {
+ printf("Out of memory\n");
+ exit(1);
+ }
+
list[list_size].len = len;
list[list_size].num = 1;
list[list_size].page_num = get_page_num(buf);
--
2.25.1


\
 
 \ /
  Last update: 2022-03-01 16:16    [W:0.033 / U:0.672 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site