42 lines
1.3 KiB
Diff
42 lines
1.3 KiB
Diff
From b51ef773ad5cbd3eb9e348df4f70eb03307ce044 Mon Sep 17 00:00:00 2001
|
|
From: EulerOSWander <314264452@qq.com>
|
|
Date: Mon, 12 Jun 2023 14:19:30 +0800
|
|
Subject: [PATCH] pmap: Increase memory allocation failure judgment
|
|
|
|
Call trace:
|
|
#0 __vsnprintf_internal
|
|
#1 0x00007f967aedd656 in __GI___snprintf
|
|
#2 0x00005612da28c707 in snprintf
|
|
#3 config_read (rc_filename=<optimized out>) at pmap.c:885
|
|
#4 0x00005612da28b8c0 int main at pmap.c:1144
|
|
|
|
The above stack is caused by calling a null pointer
|
|
after the memory allocation fails. Increase the null
|
|
pointer judgment.
|
|
|
|
signed-off-by: zhoujie <zhoujie133@huawei.com>
|
|
---
|
|
src/pmap.c | 6 +++++-
|
|
1 file changed, 5 insertions(+), 1 deletion(-)
|
|
|
|
diff --git a/src/pmap.c b/src/pmap.c
|
|
index 658b2501..74d57dab 100644
|
|
--- a/src/pmap.c
|
|
+++ b/src/pmap.c
|
|
@@ -881,7 +881,11 @@ static int config_read (char *rc_filename)
|
|
}
|
|
|
|
/* add the field in the list */
|
|
- cnf_listnode = calloc(1, sizeof *cnf_listnode);
|
|
+ if (!(cnf_listnode = calloc(1, sizeof *cnf_listnode))) {
|
|
+ xwarnx(_("memory allocation failed"));
|
|
+ fclose(f);
|
|
+ return 0;
|
|
+ }
|
|
snprintf(cnf_listnode -> description, sizeof(cnf_listnode -> description), "%s", token);
|
|
cnf_listnode -> next = cnf_listhead;
|
|
cnf_listhead = cnf_listnode;
|
|
--
|
|
2.33.0
|
|
|