mirror of
https://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git
synced 2024-12-04 23:43:51 +08:00
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>
This commit is contained in:
parent
c3215a5324
commit
af03924f5b
@ -599,6 +599,7 @@ void add_to_flist(int ft, int id, int parent)
|
|||||||
void append_pathname(pathname_t * name, char *str)
|
void append_pathname(pathname_t * name, char *str)
|
||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
|
char *path;
|
||||||
|
|
||||||
len = strlen(str);
|
len = strlen(str);
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
@ -609,7 +610,13 @@ void append_pathname(pathname_t * name, char *str)
|
|||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
#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);
|
strcpy(&name->path[name->len], str);
|
||||||
name->len += len;
|
name->len += len;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user