]> xenbits.xensource.com Git - libvirt.git/commitdiff
libxl_conf: Add check for unsupported graphics type
authorRayhan Faizel <rayhan.faizel@gmail.com>
Tue, 17 Sep 2024 17:58:46 +0000 (23:28 +0530)
committerMartin Kletzander <mkletzan@redhat.com>
Wed, 2 Oct 2024 14:06:51 +0000 (16:06 +0200)
libxlMakeVfb always succeeds regardless of if the graphics type is
actually supported or not.

libxl_defbool_val is called in libxlMakeBuildInfoVfb which besides returning
the boolean value of the defbool also has an assertion that the defbool value
is not set to default. It is possible to fail this assertion if an
unsupported graphics type is used. In libxlMakeVfb, the VNC and SDL enable
defbools are still left in their default state if the graphics type falls
outside the two, which leads to this issue.

This patch adds a check to reject graphics types outside of SDL, VNC, and SPICE
very early on in libxlMakeVfb. As a safeguard, we also initialize both vnc
enable and sdl enable defbools as false early.

Signed-off-by: Rayhan Faizel <rayhan.faizel@gmail.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
src/libxl/libxl_conf.c

index 8c91489ffd351c44f762e6fc1d0aa85c8d118123..c404226e436da30bbd267a26ac4f672ba39c121e 100644 (file)
@@ -1506,18 +1506,18 @@ libxlMakeVfb(virPortAllocatorRange *graphicsports,
     virDomainGraphicsListenDef *glisten = NULL;
 
     libxl_device_vfb_init(x_vfb);
+    libxl_defbool_set(&x_vfb->sdl.enable, 0);
+    libxl_defbool_set(&x_vfb->vnc.enable, 0);
 
     switch (l_vfb->type) {
         case VIR_DOMAIN_GRAPHICS_TYPE_SDL:
             libxl_defbool_set(&x_vfb->sdl.enable, 1);
-            libxl_defbool_set(&x_vfb->vnc.enable, 0);
             libxl_defbool_set(&x_vfb->sdl.opengl, 0);
             x_vfb->sdl.display = g_strdup(l_vfb->data.sdl.display);
             x_vfb->sdl.xauthority = g_strdup(l_vfb->data.sdl.xauth);
             break;
         case  VIR_DOMAIN_GRAPHICS_TYPE_VNC:
             libxl_defbool_set(&x_vfb->vnc.enable, 1);
-            libxl_defbool_set(&x_vfb->sdl.enable, 0);
             /* driver handles selection of free port */
             libxl_defbool_set(&x_vfb->vnc.findunused, 0);
             if (l_vfb->data.vnc.autoport) {
@@ -1542,13 +1542,18 @@ libxlMakeVfb(virPortAllocatorRange *graphicsports,
             x_vfb->keymap = g_strdup(l_vfb->data.vnc.keymap);
             break;
 
+        case VIR_DOMAIN_GRAPHICS_TYPE_SPICE:
+            break;
+
         case VIR_DOMAIN_GRAPHICS_TYPE_RDP:
         case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP:
-        case VIR_DOMAIN_GRAPHICS_TYPE_SPICE:
         case VIR_DOMAIN_GRAPHICS_TYPE_EGL_HEADLESS:
         case VIR_DOMAIN_GRAPHICS_TYPE_DBUS:
         case VIR_DOMAIN_GRAPHICS_TYPE_LAST:
-            break;
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           _("unsupported graphics type %1$s"),
+                           virDomainGraphicsTypeToString(l_vfb->type));
+            return -1;
     }
 
     return 0;