Skip to contentSkip to conversation

libxl/libxl_dm.c: u.hvm.usbdevice_list is checked for emptiness

PATCH Superseded Robin Lee 2 participants 2 messages May 5, 2017

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Robin Lee

author
#0 lore raw

PATCH 1/1 libxl/libxl_dm.c: u.hvm.usbdevice_list is checked for emptiness

Currently usbdevice_list is only checked for nullity. But the OCaml binding will convert empty list to a pointer to NULL, instead of a NULL pointer. That means the OCaml binding will fail to disable USB.

This patch will check emptiness of usbdevice_list. And NULL is still a valid empty list.

---
 tools/libxl/libxl_dm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/libxl/libxl_dm.c +2 -2
index f8ba859..a76a438 100644
@@ -559,7 +559,7 @@ static int libxl__build_device_model_args_old(libxl__gc *gc,
         }
         if (libxl_defbool_val(b_info->u.hvm.usb)
             || b_info->u.hvm.usbdevice
-            || b_info->u.hvm.usbdevice_list) {
+            || libxl_string_list_length(&b_info->u.hvm.usbdevice_list)) {
             if ( b_info->u.hvm.usbdevice && b_info->u.hvm.usbdevice_list )
             {
                 LOGD(ERROR, domid, "Both usbdevice and usbdevice_list set");
@@ -1149,7 +1149,7 @@ static int libxl__build_device_model_args_new(libxl__gc *gc,
         }
         if (libxl_defbool_val(b_info->u.hvm.usb)
             || b_info->u.hvm.usbdevice
-            || b_info->u.hvm.usbdevice_list) {
+            || libxl_string_list_length(&b_info->u.hvm.usbdevice_list)) {
             if ( b_info->u.hvm.usbdevice && b_info->u.hvm.usbdevice_list )
             {
                 LOGD(ERROR, guest_domid, "Both usbdevice and usbdevice_list set");
Signature · 7 lines
2.9.3


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#1 lore raw

Robin Lee writes ("[PATCH] libxl/libxl_dm.c: u.hvm.usbdevice_list is checked for emptiness"):

Quoted 3 lines

Currently usbdevice_list is only checked for nullity. But the OCaml binding will convert empty list to a pointer to NULL, instead of a NULL pointer. That means the OCaml binding will fail to disable USB.

Thanks for this.

Quoted 12 lines

This patch will check emptiness of usbdevice_list. And NULL is still a valid empty list.

---
 tools/libxl/libxl_dm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/libxl/libxl_dm.c +0 -0
index f8ba859..a76a438 100644

tools/libxl/libxl_dm.c static int libxl__build_device_model_args_old(libxl__gc *gc, · line 564

Quoted 7 lines
tools/libxl/libxl_dm.c +1 -1
@@ -559,7 +559,7 @@ static int libxl__build_device_model_args_old(libxl__gc *gc,
         }
         if (libxl_defbool_val(b_info->u.hvm.usb)
             || b_info->u.hvm.usbdevice
-            || b_info->u.hvm.usbdevice_list) {
+            || libxl_string_list_length(&b_info->u.hvm.usbdevice_list)) {
             if ( b_info->u.hvm.usbdevice && b_info->u.hvm.usbdevice_list )
             {

I think it would be better to add this string_list_length in the conflict check in the next line. That way if someone (eg in ocaml) specifies usbdevice but not usbdevice_list it will still work.

tools/libxl/libxl_dm.c static int libxl__build_device_model_args_new(libxl__gc *gc, · line 1153

Quoted 8 lines
tools/libxl/libxl_dm.c +1 -1
                 LOGD(ERROR, domid, "Both usbdevice and usbdevice_list set");
@@ -1149,7 +1149,7 @@ static int libxl__build_device_model_args_new(libxl__gc *gc,
         }
         if (libxl_defbool_val(b_info->u.hvm.usb)
             || b_info->u.hvm.usbdevice
-            || b_info->u.hvm.usbdevice_list) {
+            || libxl_string_list_length(&b_info->u.hvm.usbdevice_list)) {
             if ( b_info->u.hvm.usbdevice && b_info->u.hvm.usbdevice_list )

The similarity between the existing code here, and at the previous site of the bug, is quite striking, isn't it.

Thanks,
Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel