Skip to content

Commit

Permalink
ui/sdl2: fix segment fault caused by null pointer dereference
Browse files Browse the repository at this point in the history
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.

Signed-off-by: Changbin Du <changbin.du@gmail.com>
Message-id: 20200427132412.17909-1-changbin.du@gmail.com
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
  • Loading branch information
changbindu authored and kraxel committed May 14, 2020
1 parent df2ac3c commit 32ec983
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ui/sdl2.c
Expand Up @@ -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:
Expand Down Expand Up @@ -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);
}
Expand All @@ -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;
}
Expand Down

0 comments on commit 32ec983

Please sign in to comment.