qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] ui/gtk: fix NULL pointer dereference


From: Christian Schoenebeck
Subject: [PATCH] ui/gtk: fix NULL pointer dereference
Date: Sun, 7 Mar 2021 20:38:53 +0100

DisplaySurface pointer passed to gd_switch() can be NULL, so check this
before trying to dereference it.

Fixes: c821a58ee7 ("ui/console: Pass placeholder surface to display")
Reported-by: Coverity (CID 1448421)
Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
---
 ui/gtk.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/ui/gtk.c b/ui/gtk.c
index 3edaf041de..a27b27d004 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -567,7 +567,7 @@ static void gd_switch(DisplayChangeListener *dcl,
     }
     vc->gfx.ds = surface;
 
-    if (surface->format == PIXMAN_x8r8g8b8) {
+    if (surface && surface->format == PIXMAN_x8r8g8b8) {
         /*
          * PIXMAN_x8r8g8b8 == CAIRO_FORMAT_RGB24
          *
@@ -580,7 +580,7 @@ static void gd_switch(DisplayChangeListener *dcl,
              surface_width(surface),
              surface_height(surface),
              surface_stride(surface));
-    } else {
+    } else if (surface) {
         /* Must convert surface, use pixman to do it. */
         vc->gfx.convert = pixman_image_create_bits(PIXMAN_x8r8g8b8,
                                                    surface_width(surface),
-- 
2.20.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]