From: Juergen Gross Date: Tue, 2 Jun 2020 06:00:20 +0000 (+0200) Subject: tools: check return value of asprintf() in xenhypfs X-Git-Tag: archive/raspbian/4.14.0+80-gd101b417b7-1+rpi1^2~63^2~112 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=370b41113eaed780f109d708e4478a6bfb794459;p=xen.git 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 Signed-off-by: Juergen Gross Acked-by: Wei Liu Release-acked-by: Paul Durrant --- diff --git a/tools/misc/xenhypfs.c b/tools/misc/xenhypfs.c index 158b901f42..5145b8969f 100644 --- a/tools/misc/xenhypfs.c +++ b/tools/misc/xenhypfs.c @@ -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); } }