Message ID | 20210630082724.50838-7-wuguanghao3@huawei.com |
---|---|
State | Accepted |
Headers | show |
Series | [v2,01/12] profile_create_node: set magic before strdup(name) to avoid memory leak | expand |
On Wed, Jun 30, 2021 at 04:27:18PM +0800, wuguanghao wrote: > 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 segfault > > Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com> > Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com> Thanks, applied, with a minor whitespace fixup, and the commit description linewrapped. - Ted
diff --git a/contrib/fsstress.c b/contrib/fsstress.c index 2a983482..07433205 100644 --- a/contrib/fsstress.c +++ b/contrib/fsstress.c @@ -599,7 +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 if (len && *str == '/' && name->len == 0) { @@ -609,7 +609,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; }