| 
    
 [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [Patch v3 3/4] tools/libxl: Fix libxl__device_nic_from_xs_be()
 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 v3:
 * Less hypervisor coding style
 * Slightly easier-to-read error conditional for nic->mac
Changes in v2:
 * Use libxl__xs_read_checked() in preference to xs_read() and free()
---
 tools/libxl/libxl.c |   20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index 2b847ef..3237354 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -2982,24 +2982,28 @@ static void libxl__device_nic_from_xs_be(libxl__gc *gc,
 {
     libxl_ctx *ctx = libxl__gc_owner(gc);
     unsigned int len;
-    char *tmp;
+    const char *tmp;
     int rc;
 
     libxl_device_nic_init(nic);
 
-    tmp = xs_read(ctx->xsh, XBT_NULL,
-                  libxl__sprintf(gc, "%s/handle", be_path), &len);
-    if ( tmp )
+    rc = libxl__xs_read_checked(gc, XBT_NULL,
+                                libxl__sprintf(gc, "%s/handle", be_path),
+                                &tmp);
+
+    if ((rc == 0) && strlen(tmp))
         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)
+    rc = libxl__xs_read_checked(gc, XBT_NULL,
+                                libxl__sprintf(gc, "%s/mac", be_path),
+                                &tmp);
+
+    if ((rc != 0) || (strlen(tmp) == 0) ||
+        (libxl__parse_mac(tmp, nic->mac) != 0))
         memset(nic->mac, 0, sizeof(nic->mac));
 
     nic->ip = xs_read(ctx->xsh, XBT_NULL,
-- 
1.7.10.4
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel
 
 
  | 
  
![]()  | 
            
         Lists.xenproject.org is hosted with RackSpace, monitoring our  |