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

[xen staging] xenstore_client: handle memory on error



commit 00948dcd6a5412695b42c6d5045b0d3075b14114
Author:     Norbert Manthey <nmanthey@xxxxxxxxx>
AuthorDate: Fri Feb 26 15:41:38 2021 +0100
Commit:     Julien Grall <jgrall@xxxxxxxxxx>
CommitDate: Thu Apr 1 17:12:05 2021 +0100

    xenstore_client: handle memory on error
    
    In case a command fails, also free the memory. As this is for the CLI
    client, currently the leaked memory is freed right after receiving the
    error, as the application terminates next.
    
    Similarly, if the allocation fails, do not use the NULL pointer
    afterwards, but instead error out.
    
    This bug was discovered and resolved using Coverity Static Analysis
    Security Testing (SAST) by Synopsys, Inc.
    
    Signed-off-by: Norbert Manthey <nmanthey@xxxxxxxxx>
    Reviewed-by: Thomas Friebel <friebelt@xxxxxxxxx>
    Reviewed-by: Julien Grall <jgrall@xxxxxxxxxxxx>
    Reviewed-by: Juergen Gross <jgross@xxxxxxxx>
---
 tools/xenstore/xenstore_client.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tools/xenstore/xenstore_client.c b/tools/xenstore/xenstore_client.c
index 8015bfe5be..ddbafc5175 100644
--- a/tools/xenstore/xenstore_client.c
+++ b/tools/xenstore/xenstore_client.c
@@ -382,11 +382,14 @@ perform(enum mode mode, int optind, int argc, char 
**argv, struct xs_handle *xsh
                 /* Copy path, because we can't modify argv because we will 
need it
                    again if xs_transaction_end gives us EAGAIN. */
                 char *p = malloc(strlen(path) + 1);
+                if (!p)
+                    return 1;
                 strcpy(p, path);
                 path = p;
 
             again:
                 if (do_rm(path, xsh, xth)) {
+                    free(path);
                     return 1;
                 }
 
--
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®.