|
|
a77133 |
From c74301ce5020c499445eb5c32bd70e4a1099a62d Mon Sep 17 00:00:00 2001
|
|
|
a77133 |
From: wuguanghao <wuguanghao3@huawei.com>
|
|
|
a77133 |
Date: Wed, 30 Jun 2021 16:27:18 +0800
|
|
|
a77133 |
Subject: [PATCH 29/46] append_pathname: check the value returned by realloc
|
|
|
a77133 |
Content-Type: text/plain
|
|
|
a77133 |
|
|
|
a77133 |
In append_pathname(), we need to add a new path to save the value
|
|
|
a77133 |
returned by realloc, otherwise the name->path may be NULL, causing
|
|
|
a77133 |
a segfault.
|
|
|
a77133 |
|
|
|
a77133 |
Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
|
|
|
a77133 |
Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
|
|
|
a77133 |
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
|
|
|
a77133 |
Signed-off-by: Lukas Czerner <lczerner@redhat.com>
|
|
|
a77133 |
---
|
|
|
a77133 |
contrib/fsstress.c | 9 ++++++++-
|
|
|
a77133 |
1 file changed, 8 insertions(+), 1 deletion(-)
|
|
|
a77133 |
|
|
|
a77133 |
diff --git a/contrib/fsstress.c b/contrib/fsstress.c
|
|
|
a77133 |
index 2a983482..2136a903 100644
|
|
|
a77133 |
--- a/contrib/fsstress.c
|
|
|
a77133 |
+++ b/contrib/fsstress.c
|
|
|
a77133 |
@@ -599,6 +599,7 @@ void add_to_flist(int ft, int id, int parent)
|
|
|
a77133 |
void append_pathname(pathname_t * name, char *str)
|
|
|
a77133 |
{
|
|
|
a77133 |
int len;
|
|
|
a77133 |
+ char *path;
|
|
|
a77133 |
|
|
|
a77133 |
len = strlen(str);
|
|
|
a77133 |
#ifdef DEBUG
|
|
|
a77133 |
@@ -609,7 +610,13 @@ void append_pathname(pathname_t * name, char *str)
|
|
|
a77133 |
|
|
|
a77133 |
}
|
|
|
a77133 |
#endif
|
|
|
a77133 |
- name->path = realloc(name->path, name->len + 1 + len);
|
|
|
a77133 |
+ path = realloc(name->path, name->len + 1 + len);
|
|
|
a77133 |
+ if (path == NULL) {
|
|
|
a77133 |
+ fprintf(stderr, "fsstress: append_pathname realloc failed\n");
|
|
|
a77133 |
+ chdir(homedir);
|
|
|
a77133 |
+ abort();
|
|
|
a77133 |
+ }
|
|
|
a77133 |
+ name->path = path;
|
|
|
a77133 |
strcpy(&name->path[name->len], str);
|
|
|
a77133 |
name->len += len;
|
|
|
a77133 |
}
|
|
|
a77133 |
--
|
|
|
a77133 |
2.35.1
|
|
|
a77133 |
|