[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[xen staging] tools: check return value of asprintf() in xenhypfs



commit 370b41113eaed780f109d708e4478a6bfb794459
Author:     Juergen Gross <jgross@xxxxxxxx>
AuthorDate: Tue Jun 2 08:00:20 2020 +0200
Commit:     Wei Liu <wl@xxxxxxx>
CommitDate: Tue Jun 2 12:05:13 2020 +0000

    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@xxxxxxxxxx>
    Signed-off-by: Juergen Gross <jgross@xxxxxxxx>
    Acked-by: Wei Liu <wl@xxxxxxx>
    Release-acked-by: Paul Durrant <paul@xxxxxxx>
---
 tools/misc/xenhypfs.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

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);
         }
     }
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.