diff mbox series

[v3,04/12] ss_add_info_dir: don't zap the info->info_dirs and check whether

Message ID 20210728015648.284588-2-wuguanghao3@huawei.com
State Accepted
Headers show
Series e2fsprogs: some bugfixs | expand

Commit Message

wuguanghao July 28, 2021, 1:56 a.m. UTC
From: Wu Guanghao <wuguanghao3@huawei.com>

In ss_add_info_dir(), don't zap the info->info_dirs. At the same time, it is necessary
to check whether dirs[n_dirs] is a null pointer, otherwise a segmentation
fault will occur.

Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
Reviewed-by: Wu Bo <wubo40@huawei.com>
---
 lib/ss/help.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Theodore Ts'o Aug. 3, 2021, 2 a.m. UTC | #1
On Wed, Jul 28, 2021 at 09:56:45AM +0800, wuguanghao wrote:
> From: Wu Guanghao <wuguanghao3@huawei.com>
> 
> In ss_add_info_dir(), don't zap the info->info_dirs. At the same time, it is necessary
> to check whether dirs[n_dirs] is a null pointer, otherwise a segmentation
> fault will occur.
> 
> Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
> Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
> Reviewed-by: Wu Bo <wubo40@huawei.com>

Thanks, applied.

					- Ted
diff mbox series

Patch

diff --git a/lib/ss/help.c b/lib/ss/help.c
index 5204401b..b4465bfe 100644
--- a/lib/ss/help.c
+++ b/lib/ss/help.c
@@ -148,13 +148,16 @@  void ss_add_info_dir(int sci_idx, char *info_dir, int *code_ptr)
     dirs = (char **)realloc((char *)dirs,
 			    (unsigned)(n_dirs + 2)*sizeof(char *));
     if (dirs == (char **)NULL) {
-	info->info_dirs = (char **)NULL;
 	*code_ptr = errno;
 	return;
     }
     info->info_dirs = dirs;
     dirs[n_dirs + 1] = (char *)NULL;
     dirs[n_dirs] = malloc((unsigned)strlen(info_dir)+1);
+    if (dirs[n_dirs] == (char *)NULL) {
+        *code_ptr = errno;
+        return;
+    }
     strcpy(dirs[n_dirs], info_dir);
     *code_ptr = 0;
 }