tools: check return value of asprintf() in xenhypfs

asprintf() can fail, so check its return value. Additionally fix a
memory leak in xenhypfs.

Reported-by: Andrew Cooper <andrew.cooper3@citrix.com>
Signed-off-by: Juergen Gross <jgross@suse.com>
Acked-by: Wei Liu <wl@xen.org>
Release-acked-by: Paul Durrant <paul@xen.org>
This commit is contained in:
Juergen Gross authored and Wei Liu committed 2020-06-02 12:05:13 +00:00
1 parent 52a9022fe9
commit 370b41113e
1 file changed
+6 -1
+6 -1
View File
@@ -148,9 +148,14 @@ static int xenhypfs_tree_sub(char *path, unsigned int depth)
printf("%*s%s%s\n", depth * 2, "", ent[i].name,
ent[i].type == xenhypfs_type_dir ? "/" : "");
if (ent[i].type == xenhypfs_type_dir) {
asprintf(&p, "%s%s%s", path, (depth == 1) ? "" : "/", ent[i].name);
if (asprintf(&p, "%s%s%s", path, (depth == 1) ? "" : "/",
ent[i].name) < 0) {
ret = 2;
break;
}
if (xenhypfs_tree_sub(p, depth + 1))
ret = 2;
free(p);
}
}
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.