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

[xen master] tools/xenstore: Harden xs_domain_is_introduced()



commit 243036df0d55673de59c214e240b9b914d278b65
Author:     Norbert Manthey <nmanthey@xxxxxxxxx>
AuthorDate: Fri Feb 26 15:41:44 2021 +0100
Commit:     Julien Grall <jgrall@xxxxxxxxxx>
CommitDate: Wed Mar 3 18:22:06 2021 +0000

    tools/xenstore: Harden xs_domain_is_introduced()
    
    The function single_with_domid() may return NULL if something
    went wrong (e.g. XenStored returns an error or the connection is
    in bad state).
    
    They are unlikely but not impossible, so it would be better to
    return an error and allow the caller to handle it gracefully rather
    than crashing.
    
    In this case we should treat it as the domain has disappeared (i.e.
    return false) as the caller will not likely going to be able to
    communicate with XenStored again.
    
    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: Julien Grall <jgrall@xxxxxxxxxxxx>
    Reviewed-by: Raphael Ning <raphning@xxxxxxxxxxxx>
    Reviewed-by: Juergen Gross <jgross@xxxxxxxx>
    Release-Acked-by: Ian Jackson <iwj@xxxxxxxxxxxxxx>
---
 tools/libs/store/xs.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/tools/libs/store/xs.c b/tools/libs/store/xs.c
index b6ecbd787e..c91377c27f 100644
--- a/tools/libs/store/xs.c
+++ b/tools/libs/store/xs.c
@@ -1180,7 +1180,12 @@ bool xs_path_is_subpath(const char *parent, const char 
*child)
 bool xs_is_domain_introduced(struct xs_handle *h, unsigned int domid)
 {
        char *domain = single_with_domid(h, XS_IS_DOMAIN_INTRODUCED, domid);
-       int rc = strcmp("F", domain);
+       bool rc = false;
+
+       if (!domain)
+               return rc;
+
+       rc = strcmp("F", domain) != 0;
 
        free(domain);
        return rc;
--
generated by git-patchbot for /home/xen/git/xen.git#master



 


Rackspace

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