Blame SOURCES/e2fsprogs-1.45.6-ss_add_info_dir-fix-error-handling-when-memory-alloc.patch

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