From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Cooper Subject: Re: [PATCH for-4.6 13/13] tools/ocaml: handle strdup failure in stub_xl_device_disk_of_vdev Date: Thu, 23 Jul 2015 09:38:34 +0100 Message-ID: <55B0A80A.8080702@citrix.com> References: <1437638354-14216-1-git-send-email-wei.liu2@citrix.com> <1437638354-14216-14-git-send-email-wei.liu2@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1ZIC1R-0001Vl-Vw for xen-devel@lists.xenproject.org; Thu, 23 Jul 2015 08:38:34 +0000 In-Reply-To: <1437638354-14216-14-git-send-email-wei.liu2@citrix.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: Wei Liu , Xen-devel Cc: Ian Jackson , Ian Campbell , dave.scott@eu.citrix.com List-Id: xen-devel@lists.xenproject.org On 23/07/2015 08:59, Wei Liu wrote: > Signed-off-by: Wei Liu > --- > Cc: dave.scott@eu.citrix.com > > Please check if the use of caml_failwith is correct. This issue I have a different patch for, which could be 4.6 material, if it weren't for the same issue as identified in patch 12. In this case, Ocaml strings may contain embedded NULs which generally makes the use of the strxxx() functions incorrect. OTOH, the first thing libxl will do is assume that they are NUL terminated, so it probably isn't too much of a problem. There is already a dup_String_Val() function which attempts to deal with this, although it has failure cases from integer overflows. ~Andrew > --- > tools/ocaml/libs/xl/xenlight_stubs.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/tools/ocaml/libs/xl/xenlight_stubs.c b/tools/ocaml/libs/xl/xenlight_stubs.c > index 7b8d6db..dccd7ed 100644 > --- a/tools/ocaml/libs/xl/xenlight_stubs.c > +++ b/tools/ocaml/libs/xl/xenlight_stubs.c > @@ -780,6 +780,10 @@ value stub_xl_device_disk_of_vdev(value ctx, value domid, value vdev) > > c_vdev = strdup(String_val(vdev)); > > + if (!c_vdev) { > + caml_failwith("Failed to duplicate vdev string."); > + } > + > caml_enter_blocking_section(); > libxl_vdev_to_device_disk(CTX, c_domid, c_vdev, &c_disk); > caml_leave_blocking_section();