|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [Patch v2 3/4] tools/libxl: Fix libxl__device_nic_from_xs_be()
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 <andrew.cooper3@xxxxxxxxxx>
> CC: Ian Campbell <Ian.Campbell@xxxxxxxxxx>
> CC: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
> CC: Roger Pau Monne <roger.pau@xxxxxxxxxx>
>
> ---
> 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,
>
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |