Skip to contentSkip to conversation

ui/sdl2: fix segment fault caused by null pointer dereference

PATCH In review Changbin Du 2 participants 3 messages Apr 27, 2020 – May 14, 2020

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ui/sdl2: fix segment fault caused by null pointer dereference

I found SDL_GetWindowFromID() sometimes return NULL when I start qemu via ssh forwarding even the window has been crated already. I am not sure whether this is a bug of SDL, but we'd better check it carefully.

---
v2: fix typo.

---
 ui/sdl2.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
ui/sdl2.c +12 -0
index 3c9424eb42..61c7956da3 100644
@@ -332,6 +332,10 @@ static void handle_keydown(SDL_Event *ev)
     int gui_key_modifier_pressed = get_mod_state();
     int gui_keysym = 0;
 
+    if (!scon) {
+        return;
+    }
+
     if (!scon->ignore_hotkeys && gui_key_modifier_pressed && !ev->key.repeat) {
         switch (ev->key.keysym.scancode) {
         case SDL_SCANCODE_2:
@@ -412,6 +416,10 @@ static void handle_keyup(SDL_Event *ev)
 {
     struct sdl2_console *scon = get_scon_from_window(ev->key.windowID);
 
+    if (!scon) {
+        return;
+    }
+
     scon->ignore_hotkeys = false;
     sdl2_process_key(scon, &ev->key);
 }
@@ -421,6 +429,10 @@ static void handle_textinput(SDL_Event *ev)
     struct sdl2_console *scon = get_scon_from_window(ev->text.windowID);
     QemuConsole *con = scon ? scon->dcl.con : NULL;
 
+    if (!con) {
+        return;
+    }
+
     if (qemu_console_is_graphic(con)) {
         return;
     }
Signature · 1 line
2.25.1
#1 lore raw

hello, is this ready to merge now?

Quoted 52 lines · Changbin Du

I found SDL_GetWindowFromID() sometimes return NULL when I start qemu via ssh forwarding even the window has been crated already. I am not sure whether this is a bug of SDL, but we'd better check it carefully.

---
v2: fix typo.

---
 ui/sdl2.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
ui/sdl2.c +12 -0
index 3c9424eb42..61c7956da3 100644
@@ -332,6 +332,10 @@ static void handle_keydown(SDL_Event *ev)
     int gui_key_modifier_pressed = get_mod_state();
     int gui_keysym = 0;
 
+    if (!scon) {
+        return;
+    }
+
     if (!scon->ignore_hotkeys && gui_key_modifier_pressed && !ev->key.repeat) {
         switch (ev->key.keysym.scancode) {
         case SDL_SCANCODE_2:
@@ -412,6 +416,10 @@ static void handle_keyup(SDL_Event *ev)
 {
     struct sdl2_console *scon = get_scon_from_window(ev->key.windowID);
 
+    if (!scon) {
+        return;
+    }
+
     scon->ignore_hotkeys = false;
     sdl2_process_key(scon, &ev->key);
 }
@@ -421,6 +429,10 @@ static void handle_textinput(SDL_Event *ev)
     struct sdl2_console *scon = get_scon_from_window(ev->text.windowID);
     QemuConsole *con = scon ? scon->dcl.con : NULL;
 
+    if (!con) {
+        return;
+    }
+
     if (qemu_console_is_graphic(con)) {
         return;
     }
Signature · 1 line
2.25.1
Signature · 2 lines
Cheers,
Changbin Du
#2 lore raw
Quoted 8 lines · Changbin Du

hello, is this ready to merge now?

Quoted 5 lines · Changbin Du

I found SDL_GetWindowFromID() sometimes return NULL when I start qemu via ssh forwarding even the window has been crated already. I am not sure whether this is a bug of SDL, but we'd better check it carefully.

Added to ui queue now.

thanks,
Gerd