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>
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);
}
}