]> xenbits.xensource.com Git - xen.git/commitdiff
libxl: don't segfault when creating domain with invalid pvusb device
authorJuergen Gross <jgross@suse.com>
Wed, 8 Feb 2017 13:34:08 +0000 (14:34 +0100)
committerWei Liu <wei.liu2@citrix.com>
Wed, 8 Feb 2017 15:00:02 +0000 (15:00 +0000)
Creating a domain with an invalid controller specification for a pvusb
device will currently segfault.

Avoid this by bailing out early in case of a mandatory xenstore path
not existing.

Signed-of-by: Juergen Gross <jgross@suse.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
tools/libxl/libxl_internal.h
tools/libxl/libxl_usb.c
tools/libxl/libxl_xshelp.c

index 5f46578b9b3b8e0411df40665d7509ea9625db14..a093bc62eebc07bc1b5fb13bacc9578ffc4b52ca 100644 (file)
@@ -736,6 +736,13 @@ int libxl__xs_mknod(libxl__gc *gc, xs_transaction_t t,
                     const char *path, struct xs_permissions *perms,
                     unsigned int num_perms);
 
+/* On success, *result_out came from the gc.
+ * On error, *result_out is undefined.
+ * ENOENT is regarded as error.
+ */
+int libxl__xs_read_mandatory(libxl__gc *gc, xs_transaction_t t,
+                             const char *path, const char **result_out);
+
 /* On success, *result_out came from the gc.
  * On error, *result_out is undefined.
  * ENOENT counts as success but sets *result_out=0
index ea7a2abed4ed52205feb2c8b2432d467a93a545e..d8948d5212c1fdf4c08c7d7467531fe3de8dab17 100644 (file)
@@ -652,9 +652,9 @@ int libxl_device_usbctrl_getinfo(libxl_ctx *ctx, uint32_t domid,
     usbctrlinfo->devid = usbctrl->devid;
 
 #define READ_SUBPATH(path, subpath) ({                                  \
-        rc = libxl__xs_read_checked(gc, XBT_NULL,                       \
-                                    GCSPRINTF("%s/" subpath, path),     \
-                                    &tmp);                              \
+        rc = libxl__xs_read_mandatory(gc, XBT_NULL,                     \
+                                      GCSPRINTF("%s/" subpath, path),   \
+                                      &tmp);                            \
         if (rc) goto out;                                               \
         (char *)tmp;                                                    \
     })
index a50805fcec67d72f1ef8318a79f8b9d0f89ab828..c4a18df353acb1da49cb35e149b42ee00fcb4773 100644 (file)
@@ -193,6 +193,18 @@ char *libxl__xs_libxl_path(libxl__gc *gc, uint32_t domid)
     return s;
 }
 
+int libxl__xs_read_mandatory(libxl__gc *gc, xs_transaction_t t,
+                             const char *path, const char **result_out)
+{
+    char *result = libxl__xs_read(gc, t, path);
+    if (!result) {
+        LOGE(ERROR, "xenstore read failed: `%s'", path);
+        return ERROR_FAIL;
+    }
+    *result_out = result;
+    return 0;
+}
+
 int libxl__xs_read_checked(libxl__gc *gc, xs_transaction_t t,
                            const char *path, const char **result_out)
 {