From mboxrd@z Thu Jan 1 00:00:00 1970 From: Wei Liu Subject: Re: [PATCH v3 1/2] libxc: Don't write terminating NULL character to command string Date: Thu, 7 Jan 2016 11:19:49 +0000 Message-ID: <20160107111949.GV27789@citrix.com> References: <1452110602-3570-1-git-send-email-boris.ostrovsky@oracle.com> <1452110602-3570-2-git-send-email-boris.ostrovsky@oracle.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Content-Disposition: inline In-Reply-To: <1452110602-3570-2-git-send-email-boris.ostrovsky@oracle.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Boris Ostrovsky Cc: jgross@suse.com, wei.liu2@citrix.com, ian.campbell@citrix.com, stefano.stabellini@eu.citrix.com, andrew.cooper3@citrix.com, ian.jackson@eu.citrix.com, xen-devel@lists.xen.org, roger.pau@citrix.com List-Id: xen-devel@lists.xenproject.org On Wed, Jan 06, 2016 at 03:03:21PM -0500, Boris Ostrovsky wrote: > 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 Acked-by: Wei Liu > --- > tools/libxc/xc_dom_x86.c | 3 +-- > 1 files changed, 1 insertions(+), 2 deletions(-) > > diff --git a/tools/libxc/xc_dom_x86.c b/tools/libxc/xc_dom_x86.c > index 3960875..b8d2904 100644 > --- a/tools/libxc/xc_dom_x86.c > +++ b/tools/libxc/xc_dom_x86.c > @@ -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); > } > -- > 1.7.1 >