diff mbox

[v2] libxc: fix uninitialised usage of rc in meminit_hvm

Message ID 1454505683-2534-1-git-send-email-roger.pau@citrix.com (mailing list archive)
State New, archived
Headers show

Commit Message

Roger Pau Monné Feb. 3, 2016, 1:21 p.m. UTC
From: Roger Pau Monne <royger@FreeBSD.org>

Due to the HVMlite changes there's a chance that the value in rc is checked
without being initialised. Fix this by initialising it to 0 prior to the
while loop. Also add a specific error check to a previous populate_physmap
call, this prevents us from overwriting this error.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reported-by: Olaf Hering <olaf@aepfle.de>
---
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Ian Campbell <ian.campbell@citrix.com>
Cc: Wei Liu <wei.liu2@citrix.com>
---
Changes since v1:
 - Only set rc = 0 prior to the while loop.
 - Add an error check to the previous populate_physmap call.
---
 tools/libxc/xc_dom_x86.c | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Ian Campbell Feb. 4, 2016, 4:20 p.m. UTC | #1
On Wed, 2016-02-03 at 14:21 +0100, Roger Pau Monne wrote:
> From: Roger Pau Monne <royger@FreeBSD.org>

I dropped this as discussed on IRC.

> Due to the HVMlite changes there's a chance that the value in rc is
> checked
> without being initialised. Fix this by initialising it to 0 prior to the
> while loop. Also add a specific error check to a previous
> populate_physmap
> call, this prevents us from overwriting this error.
> 
> Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
> Reported-by: Olaf Hering <olaf@aepfle.de>

Acked + Applied.
diff mbox

Patch

diff --git a/tools/libxc/xc_dom_x86.c b/tools/libxc/xc_dom_x86.c
index ef474a8..2a3f64b 100644
--- a/tools/libxc/xc_dom_x86.c
+++ b/tools/libxc/xc_dom_x86.c
@@ -1412,8 +1412,15 @@  static int meminit_hvm(struct xc_dom_image *dom)
      * ensure that we can be preempted and hence dom0 remains responsive.
      */
     if ( dom->device_model )
+    {
         rc = xc_domain_populate_physmap_exact(
             xch, domid, 0xa0, 0, memflags, &dom->p2m_host[0x00]);
+        if ( rc != 0 )
+        {
+            DOMPRINTF("Could not populate low memory (< 0xA0).\n");
+            goto error_out;
+        }
+    }
 
     stat_normal_pages = 0;
     for ( vmemid = 0; vmemid < nr_vmemranges; vmemid++ )
@@ -1440,6 +1447,7 @@  static int meminit_hvm(struct xc_dom_image *dom)
         else
             cur_pages = vmemranges[vmemid].start >> PAGE_SHIFT;
 
+        rc = 0;
         while ( (rc == 0) && (end_pages > cur_pages) )
         {
             /* Clip count to maximum 1GB extent. */