xenstat: Fix buffer over-run with new_domains being negative.
PATCH 1/1 xenstat: Fix buffer over-run with new_domains being negative.
Coverity identified this as:
CID 1055740 Out-of-bounds read - "In xenstat_get_node:
Out-of-bounds read from a buffer (CWE-125)"
And sure enough, if xc_domain_getinfolist returns us -1, we will try to use it later on in the for (i = 0; i < new_domains; ..) loop.
--- tools/xenstat/libxenstat/src/xenstat.c | 14 +++++++++----- 1 files changed, 9 insertions(+), 5 deletions(-)
tools/xenstat/libxenstat/src/xenstat.c +9 -5
@@ -208,15 +208,15 @@ xenstat_node *xenstat_get_node(xenstat_handle * handle, unsigned int flags) node->num_domains,DOMAIN_CHUNK_SIZE , domaininfo); +if (new_domains <0 ) + goto err; tmp =realloc (node->domains, (node->num_domains + new_domains) *sizeof (xenstat_domain)); -if (tmp ==NULL ) { -free (node->domains); -free (node); -return NULL ; - } +if (tmp ==NULL ) + goto err; + node->domains = tmp; domain = node->domains + node->num_domains;
@@ -280,6 +280,10 @@ xenstat_node *xenstat_get_node(xenstat_handle * handle, unsigned int flags) }return node; +err: +free (node->domains); +free (node); +return NULL ; }void xenstat_free_node (xenstat_node * node)
Signature · 1 line
1.7.7.6
Quoted 10 lines · Konrad Rzeszutek Wilk
Coverity identified this as:
CID 1055740 Out-of-bounds read - "Inxenstat_get_node:
Out-of-bounds read from a buffer (CWE-125)"And sure enough, if
xc_domain_getinfolistreturns us -1, we will try to use it later on in the for (i = 0; i <new_domains; ..) loop.Signed-off-by Konrad Rzeszutek Wilk <[email protected]>
Quoted 40 lines
--- tools/xenstat/libxenstat/src/xenstat.c | 14 +++++++++----- 1 files changed, 9 insertions(+), 5 deletions(-)tools/xenstat/libxenstat/src/xenstat.c +9
-5@@ -208,15 +208,15 @@ xenstat_node *xenstat_get_node(xenstat_handle * handle, unsigned int flags) node->num_domains,DOMAIN_CHUNK_SIZE , domaininfo); +if (new_domains <0 ) + goto err; tmp =realloc (node->domains, (node->num_domains + new_domains) *sizeof (xenstat_domain)); -if (tmp ==NULL ) { -free (node->domains); -free (node); -return NULL ; - } +if (tmp ==NULL ) + goto err; + node->domains = tmp; domain = node->domains + node->num_domains;@@ -280,6 +280,10 @@ xenstat_node *xenstat_get_node(xenstat_handle * handle, unsigned int flags) }return node; +err: +free (node->domains); +free (node); +return NULL ; }void xenstat_free_node (xenstat_node * node)
Ian Campbell
AppliedQuoted 5 lines · Andrew Cooper
Quoted 4 lines · Konrad Rzeszutek Wilk
Coverity identified this as:
CID 1055740 Out-of-bounds read - "Inxenstat_get_node:
Out-of-bounds read from a buffer (CWE-125)"
Quoted 8 lines
Quoted 6 lines
And sure enough, if
xc_domain_getinfolistreturns us -1, we will try to use it later on in the for (i = 0; i <new_domains; ..) loop.Signed-off-by Konrad Rzeszutek Wilk <[email protected]>Reviewed-by Andrew Cooper <[email protected]>
Applied.