Skip to contentSkip to conversation

gtk: Skip drawing if console surface is NULL

PATCH In review Weifeng Liu 3 participants 3 messages Jul 14, 2025 – Jul 15, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gtk: Skip drawing if console surface is NULL

In gtk draw/render callbacks, add an early NULL check for the console surface and skip drawing if it's NULL. Otherwise, attempting to fetch its width and height crash. This change fixes Coverity CID 1610328.

In practice, this case wouldn't happen at all because we always install a placeholder surface to the console when there is nothing to display.

Resolves: Coverity CID 1610328

---
 ui/gtk-egl.c     | 5 +----
 ui/gtk-gl-area.c | 5 +----
 2 files changed, 2 insertions(+), 8 deletions(-)
ui/gtk-egl.c +1 -4
index 0b787bea25..ae9239999c 100644
@@ -72,7 +72,7 @@ void gd_egl_draw(VirtualConsole *vc)
 #endif
     int ww, wh, pw, ph, gs;
 
-    if (!vc->gfx.gls) {
+    if (!vc->gfx.gls || !vc->gfx.ds) {
         return;
     }
 
@@ -112,9 +112,6 @@ void gd_egl_draw(VirtualConsole *vc)
         }
 #endif
     } else {
-        if (!vc->gfx.ds) {
-            return;
-        }
         eglMakeCurrent(qemu_egl_display, vc->gfx.esurface,
                        vc->gfx.esurface, vc->gfx.ectx);
 
ui/gtk-gl-area.c +1 -4
index 8151cc413c..05fc38096e 100644
@@ -48,7 +48,7 @@ void gd_gl_area_draw(VirtualConsole *vc)
     int fbw, fbh;
     int wx_offset, wy_offset;
 
-    if (!vc->gfx.gls) {
+    if (!vc->gfx.gls || !vc->gfx.ds) {
         return;
     }
 
@@ -135,9 +135,6 @@ void gd_gl_area_draw(VirtualConsole *vc)
         }
 #endif
     } else {
-        if (!vc->gfx.ds) {
-            return;
-        }
         gtk_gl_area_make_current(GTK_GL_AREA(vc->gfx.drawing_area));
 
         surface_gl_setup_viewport(vc->gfx.gls, vc->gfx.ds, pw, ph);
Signature · 1 line
2.49.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Weifeng Liu

In gtk draw/render callbacks, add an early NULL check for the console surface and skip drawing if it's NULL. Otherwise, attempting to fetch its width and height crash. This change fixes Coverity CID 1610328.

In practice, this case wouldn't happen at all because we always install a placeholder surface to the console when there is nothing to display.

Resolves: Coverity CID 1610328

Quoted 54 lines
---
 ui/gtk-egl.c     | 5 +----
 ui/gtk-gl-area.c | 5 +----
 2 files changed, 2 insertions(+), 8 deletions(-)
ui/gtk-egl.c +1 -4
index 0b787bea25..ae9239999c 100644
@@ -72,7 +72,7 @@ void gd_egl_draw(VirtualConsole *vc)
 #endif
     int ww, wh, pw, ph, gs;
 
-    if (!vc->gfx.gls) {
+    if (!vc->gfx.gls || !vc->gfx.ds) {
         return;
     }
 
@@ -112,9 +112,6 @@ void gd_egl_draw(VirtualConsole *vc)
         }
 #endif
     } else {
-        if (!vc->gfx.ds) {
-            return;
-        }
         eglMakeCurrent(qemu_egl_display, vc->gfx.esurface,
                        vc->gfx.esurface, vc->gfx.ectx);
 
ui/gtk-gl-area.c +1 -5
index 8151cc413c..05fc38096e 100644
@@ -48,7 +48,7 @@ void gd_gl_area_draw(VirtualConsole *vc)
     int fbw, fbh;
     int wx_offset, wy_offset;
 
-    if (!vc->gfx.gls) {
+    if (!vc->gfx.gls || !vc->gfx.ds) {
         return;
     }
 
@@ -135,9 +135,6 @@ void gd_gl_area_draw(VirtualConsole *vc)
         }
 #endif
     } else {
-        if (!vc->gfx.ds) {
-            return;
-        }
         gtk_gl_area_make_current(GTK_GL_AREA(vc->gfx.drawing_area));
 
         surface_gl_setup_viewport(vc->gfx.gls, vc->gfx.ds, pw, ph);
--

2.49.0

Signature · 1 line
Marc-André Lureau
Reviewed-by on v1 1/1
#2 lore raw
In reply to Weifeng Liu
Quoted 9 lines · Weifeng Liu

In gtk draw/render callbacks, add an early NULL check for the console surface and skip drawing if it's NULL. Otherwise, attempting to fetch its width and height crash. This change fixes Coverity CID 1610328.

In practice, this case wouldn't happen at all because we always install a placeholder surface to the console when there is nothing to display.

Resolves: Coverity CID 1610328