]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/xen.git/commitdiff
libxc: Don't write terminating NULL character to command string
authorBoris Ostrovsky <boris.ostrovsky@oracle.com>
Wed, 6 Jan 2016 20:03:21 +0000 (15:03 -0500)
committerIan Campbell <ian.campbell@citrix.com>
Thu, 7 Jan 2016 12:51:06 +0000 (12:51 +0000)
When copying boot command string for HVMlite guests we explicitly write
'\0' at MAX_GUEST_CMDLINE offset. Unless the string is close to
MAX_GUEST_CMDLINE in length this write will end up in the wrong place,
beyond the end of the mapped range.

We don't need to limit the size of command string to some arbitrary
number. Any size that can be successfully allocated and mapped is valid
and so the string is guaranteed to be NULL-terminated (since we use
strlen, which needs terminating '\0', to calculate allocation size).

Signed-off-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
tools/libxc/xc_dom_x86.c

index 39608752d0bbf439cc2ac17befc86e27a1b3e31f..b8d290464bdb733752af1ed870072f7bb1cdfee3 100644 (file)
@@ -676,8 +676,7 @@ static int alloc_magic_pages_hvm(struct xc_dom_image *dom)
 
         if ( dom->cmdline )
         {
-            strncpy(cmdline, dom->cmdline, MAX_GUEST_CMDLINE);
-            cmdline[MAX_GUEST_CMDLINE - 1] = '\0';
+            strncpy(cmdline, dom->cmdline, cmdline_size);
             start_info->cmdline_paddr = (seg.pfn << PAGE_SHIFT) +
                                 ((uintptr_t)cmdline - (uintptr_t)start_info);
         }