Skip to content

Commit

Permalink
tools/xenstore: Harden xs_domain_is_introduced()
Browse files Browse the repository at this point in the history
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@amazon.de>
Reviewed-by: Julien Grall <jgrall@amazon.co.uk>
Reviewed-by: Raphael Ning <raphning@amazon.co.uk>
Reviewed-by: Juergen Gross <jgross@suse.com>
Release-Acked-by: Ian Jackson <iwj@xenproject.org>
  • Loading branch information
nmanthey authored and Julien Grall committed Mar 3, 2021
1 parent ff3e7e7 commit 243036d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion tools/libs/store/xs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 243036d

Please sign in to comment.