]> xenbits.xensource.com Git - xen.git/commitdiff
libxc: fix out of range shift in populate_acpi_pages
authorWei Liu <wei.liu2@citrix.com>
Wed, 28 Sep 2016 15:38:19 +0000 (16:38 +0100)
committerWei Liu <wei.liu2@citrix.com>
Wed, 28 Sep 2016 15:51:50 +0000 (16:51 +0100)
unsigned int is only 4-byte long and "4" is treated as int. The shift
would overflow.

Use unsigned long type, calculate the bits to shift before shifting
instead of shifting twice.

Caught by clang compilation test.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
tools/libxc/xc_dom_core.c

index 87b450c9bb53968c2570b51d0d4fc039b1689e64..5884cdb481120a8b0b6f8edae60d383f6c939d26 100644 (file)
@@ -1048,7 +1048,7 @@ static int populate_acpi_pages(struct xc_dom_image *dom,
     xc_interface *xch = dom->xch;
     uint32_t domid = dom->guest_domid;
     unsigned long idx;
-    unsigned int first_high_idx = (4 << 30) >> PAGE_SHIFT; /* 4GB */
+    unsigned long first_high_idx = 4UL << (30 - PAGE_SHIFT); /* 4GB */
 
     for ( ; num_pages; num_pages--, extents++ )
     {