|
|
9119d9 |
From f298d86936d05d3378edb23776dfcbc043bed2ff Mon Sep 17 00:00:00 2001
|
|
|
9119d9 |
Message-Id: <f298d86936d05d3378edb23776dfcbc043bed2ff@dist-git>
|
|
|
9119d9 |
From: John Ferlan <jferlan@redhat.com>
|
|
|
9119d9 |
Date: Mon, 15 Sep 2014 15:13:55 -0400
|
|
|
9119d9 |
Subject: [PATCH] virsh: Resolve Coverity NEGATIVE_RETURNS
|
|
|
9119d9 |
|
|
|
9119d9 |
https://bugzilla.redhat.com/show_bug.cgi?id=1141209
|
|
|
9119d9 |
|
|
|
9119d9 |
Coverity notes that after we VIR_ALLOC_N(params, nparams) a failed call to
|
|
|
9119d9 |
virDomainGetCPUStats could result in nparams being set to -1. In that case,
|
|
|
9119d9 |
the subsequent virTypedParamsFree in cleanup will pass -1 which isn't good.
|
|
|
9119d9 |
|
|
|
9119d9 |
Use the returned value as the number of stats to display in the loop as
|
|
|
9119d9 |
it will be the value reported from the hypervisor and may be less than
|
|
|
9119d9 |
nparams which is OK
|
|
|
9119d9 |
|
|
|
9119d9 |
Signed-off-by: John Ferlan <jferlan@redhat.com>
|
|
|
9119d9 |
(cherry picked from commit be365d8dff1aec37b9a487ca31abce3f904419dd)
|
|
|
9119d9 |
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
|
|
|
9119d9 |
---
|
|
|
9119d9 |
tools/virsh-domain.c | 7 ++++---
|
|
|
9119d9 |
1 file changed, 4 insertions(+), 3 deletions(-)
|
|
|
9119d9 |
|
|
|
9119d9 |
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
|
|
|
9119d9 |
index 1ff264e..3e974e0 100644
|
|
|
9119d9 |
--- a/tools/virsh-domain.c
|
|
|
9119d9 |
+++ b/tools/virsh-domain.c
|
|
|
9119d9 |
@@ -6525,7 +6525,7 @@ cmdCPUStats(vshControl *ctl, const vshCmd *cmd)
|
|
|
9119d9 |
{
|
|
|
9119d9 |
virDomainPtr dom;
|
|
|
9119d9 |
virTypedParameterPtr params = NULL;
|
|
|
9119d9 |
- int pos, max_id, cpu = 0, show_count = -1, nparams = 0;
|
|
|
9119d9 |
+ int pos, max_id, cpu = 0, show_count = -1, nparams = 0, stats_per_cpu;
|
|
|
9119d9 |
size_t i, j;
|
|
|
9119d9 |
bool show_total = false, show_per_cpu = false;
|
|
|
9119d9 |
unsigned int flags = 0;
|
|
|
9119d9 |
@@ -6644,11 +6644,12 @@ cmdCPUStats(vshControl *ctl, const vshCmd *cmd)
|
|
|
9119d9 |
goto cleanup;
|
|
|
9119d9 |
|
|
|
9119d9 |
/* passing start_cpu == -1 gives us domain's total status */
|
|
|
9119d9 |
- if ((nparams = virDomainGetCPUStats(dom, params, nparams, -1, 1, flags)) < 0)
|
|
|
9119d9 |
+ if ((stats_per_cpu = virDomainGetCPUStats(dom, params, nparams,
|
|
|
9119d9 |
+ -1, 1, flags)) < 0)
|
|
|
9119d9 |
goto failed_stats;
|
|
|
9119d9 |
|
|
|
9119d9 |
vshPrint(ctl, _("Total:\n"));
|
|
|
9119d9 |
- for (i = 0; i < nparams; i++) {
|
|
|
9119d9 |
+ for (i = 0; i < stats_per_cpu; i++) {
|
|
|
9119d9 |
vshPrint(ctl, "\t%-12s ", params[i].field);
|
|
|
9119d9 |
if ((STREQ(params[i].field, VIR_DOMAIN_CPU_STATS_CPUTIME) ||
|
|
|
9119d9 |
STREQ(params[i].field, VIR_DOMAIN_CPU_STATS_USERTIME) ||
|
|
|
9119d9 |
--
|
|
|
9119d9 |
2.1.0
|
|
|
9119d9 |
|