aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwuguanghao <wuguanghao3@huawei.com>2021-06-30 16:27:18 +0800
committerTheodore Ts'o <tytso@mit.edu>2021-07-15 23:38:36 -0400
commitaf03924f5b43b325a436d07ee1222f42e3aa96b6 (patch)
treef5749e6ec2f8946d1611cc3069cc3d9b1e494946
parentc3215a532441a9a397d1b12c63827e8f7233938b (diff)
downloade2fsprogs-af03924f5b43b325a436d07ee1222f42e3aa96b6.tar.gz
append_pathname: check the value returned by realloc
In append_pathname(), we need to add a new path to save the value returned by realloc, otherwise the name->path may be NULL, causing a segfault. Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com> Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
-rw-r--r--contrib/fsstress.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/contrib/fsstress.c b/contrib/fsstress.c
index 2a983482e..2136a9034 100644
--- a/contrib/fsstress.c
+++ b/contrib/fsstress.c
@@ -599,6 +599,7 @@ void add_to_flist(int ft, int id, int parent)
void append_pathname(pathname_t * name, char *str)
{
int len;
+ char *path;
len = strlen(str);
#ifdef DEBUG
@@ -609,7 +610,13 @@ void append_pathname(pathname_t * name, char *str)
}
#endif
- name->path = realloc(name->path, name->len + 1 + len);
+ path = realloc(name->path, name->len + 1 + len);
+ if (path == NULL) {
+ fprintf(stderr, "fsstress: append_pathname realloc failed\n");
+ chdir(homedir);
+ abort();
+ }
+ name->path = path;
strcpy(&name->path[name->len], str);
name->len += len;
}