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