|
|
f239de |
From 7fa914a178bbda39e3ed75326e18b183784fd57e Mon Sep 17 00:00:00 2001
|
|
|
f239de |
From: Wu Guanghao <wuguanghao3@huawei.com>
|
|
|
f239de |
Date: Wed, 28 Jul 2021 09:56:45 +0800
|
|
|
f239de |
Subject: [PATCH 35/46] ss_add_info_dir: fix error handling when memory
|
|
|
f239de |
allocation fails
|
|
|
f239de |
Content-Type: text/plain
|
|
|
f239de |
|
|
|
f239de |
If the realloc() and malloc() calls fail, avoid a memory leak as well
|
|
|
f239de |
as a potential seg fault.
|
|
|
f239de |
|
|
|
f239de |
[ Fix error code setting to avoid depending on malloc() and realloc()
|
|
|
f239de |
setting errno. -- TYT ]
|
|
|
f239de |
|
|
|
f239de |
Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
|
|
|
f239de |
Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
|
|
|
f239de |
Reviewed-by: Wu Bo <wubo40@huawei.com>
|
|
|
f239de |
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
|
|
|
f239de |
Signed-off-by: Lukas Czerner <lczerner@redhat.com>
|
|
|
f239de |
---
|
|
|
f239de |
lib/ss/help.c | 7 +++++--
|
|
|
f239de |
1 file changed, 5 insertions(+), 2 deletions(-)
|
|
|
f239de |
|
|
|
f239de |
diff --git a/lib/ss/help.c b/lib/ss/help.c
|
|
|
f239de |
index 5204401b..96eb1092 100644
|
|
|
f239de |
--- a/lib/ss/help.c
|
|
|
f239de |
+++ b/lib/ss/help.c
|
|
|
f239de |
@@ -148,13 +148,16 @@ void ss_add_info_dir(int sci_idx, char *info_dir, int *code_ptr)
|
|
|
f239de |
dirs = (char **)realloc((char *)dirs,
|
|
|
f239de |
(unsigned)(n_dirs + 2)*sizeof(char *));
|
|
|
f239de |
if (dirs == (char **)NULL) {
|
|
|
f239de |
- info->info_dirs = (char **)NULL;
|
|
|
f239de |
- *code_ptr = errno;
|
|
|
f239de |
+ *code_ptr = ENOMEM;
|
|
|
f239de |
return;
|
|
|
f239de |
}
|
|
|
f239de |
info->info_dirs = dirs;
|
|
|
f239de |
dirs[n_dirs + 1] = (char *)NULL;
|
|
|
f239de |
dirs[n_dirs] = malloc((unsigned)strlen(info_dir)+1);
|
|
|
f239de |
+ if (dirs[n_dirs] == (char *)NULL) {
|
|
|
f239de |
+ *code_ptr = ENOMEM;
|
|
|
f239de |
+ return;
|
|
|
f239de |
+ }
|
|
|
f239de |
strcpy(dirs[n_dirs], info_dir);
|
|
|
f239de |
*code_ptr = 0;
|
|
|
f239de |
}
|
|
|
f239de |
--
|
|
|
f239de |
2.35.1
|
|
|
f239de |
|