diff mbox series

[v2,09/12] lib/ss/error.c: check return value malloc in ss_name()

Message ID 20210630082724.50838-10-wuguanghao3@huawei.com
State Accepted
Headers show
Series [v2,01/12] profile_create_node: set magic before strdup(name) to avoid memory leak | expand

Commit Message

wuguanghao June 30, 2021, 8:27 a.m. UTC
From: Zhiqiang Liu <liuzhiqiang26@huawei.com>

In ss_name(), we should check return value of malloc(),
otherwise, it may cause a segmentation fault problem.

Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
---
 lib/ss/error.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Theodore Ts'o July 16, 2021, 3:46 a.m. UTC | #1
On Wed, Jun 30, 2021 at 04:27:21PM +0800, wuguanghao wrote:
> From: Zhiqiang Liu <liuzhiqiang26@huawei.com>
> 
> In ss_name(), we should check return value of malloc(),
> otherwise, it may cause a segmentation fault problem.

Thanks, applied.

					- Ted
diff mbox series

Patch

diff --git a/lib/ss/error.c b/lib/ss/error.c
index 8d345a9f..656b71be 100644
--- a/lib/ss/error.c
+++ b/lib/ss/error.c
@@ -42,6 +42,8 @@  char *ss_name(int sci_idx)
 			 (strlen(infop->subsystem_name)+
 			  strlen(infop->current_request)+
 			  4));
+	if (ret_val == (char *)NULL)
+		return ((char *)NULL);
 	cp = ret_val;
 	cp1 = infop->subsystem_name;
 	while (*cp1)