From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?ISO-8859-1?Q?Roger_Pau_Monn=E9?= Subject: Re: [Patch v2 3/4] tools/libxl: Fix libxl__device_nic_from_xs_be() Date: Mon, 25 Nov 2013 19:52:23 +0100 Message-ID: <52939C67.7020108@citrix.com> References: <529336D0.9000707@citrix.com> <1385392759-12301-1-git-send-email-andrew.cooper3@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1385392759-12301-1-git-send-email-andrew.cooper3@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: Andrew Cooper , Xen-devel Cc: Ian Jackson , Ian Campbell List-Id: xen-devel@lists.xenproject.org On 25/11/13 16:19, Andrew Cooper wrote: > Coverity ID: 1055886 > > Replace uses of xs_read() with libxl__xs_read_checked() which appropriately > garbage-collects the allocated string, and avoid executing > libxl__parse_mac(NULL,) if the second xenstore read fails. > > Signed-off-by: Andrew Cooper > CC: Ian Campbell > CC: Ian Jackson > CC: Roger Pau Monne > > --- > Changes in v2: > * Use libxl__xs_read_checked() in preference to xs_read() and free() > --- > tools/libxl/libxl.c | 18 +++++++++--------- > 1 file changed, 9 insertions(+), 9 deletions(-) > > diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c > index 2b847ef..52f4c68 100644 > --- a/tools/libxl/libxl.c > +++ b/tools/libxl/libxl.c > @@ -2982,24 +2982,24 @@ static void libxl__device_nic_from_xs_be(libxl__gc *gc, > { > libxl_ctx *ctx = libxl__gc_owner(gc); > unsigned int len; > - char *tmp; > - int rc; > + const char *tmp; > > libxl_device_nic_init(nic); > > - tmp = xs_read(ctx->xsh, XBT_NULL, > - libxl__sprintf(gc, "%s/handle", be_path), &len); > - if ( tmp ) > + if ( (libxl__xs_read_checked(gc, XBT_NULL, > + libxl__sprintf(gc, "%s/handle", be_path), > + &tmp) == 0) && strlen(tmp) ) libxl coding style doesn't add spaces between parentheses. Also, consider using rc instead of directly checking the return value of the function. > nic->devid = atoi(tmp); > else > nic->devid = 0; > > /* nic->mtu = */ > > - tmp = xs_read(ctx->xsh, XBT_NULL, > - libxl__sprintf(gc, "%s/mac", be_path), &len); > - rc = libxl__parse_mac(tmp, nic->mac); > - if (rc) > + if ( (libxl__xs_read_checked(gc, XBT_NULL, > + libxl__sprintf(gc, "%s/mac", be_path), > + &tmp) != 0) || > + (strlen(tmp) == 0) || > + (libxl__parse_mac(tmp, nic->mac) != 0) ) No inner spaces in parentheses and use rc to keep this if condition much more readable IMHO. Roger. > memset(nic->mac, 0, sizeof(nic->mac)); > > nic->ip = xs_read(ctx->xsh, XBT_NULL, >