[hatari-devel] fix null pointer dereference in Dialog_HaltDlg

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


Or more accurately, in SDLGui_CenterDlg, but Dialog_HaltDlg is effectively responsible for the dereference:

Thread 1 "hatari" received signal SIGSEGV, Segmentation fault.
0x0000555555fcf152 in SDLGui_CenterDlg (dlg=dlg@entry=0x5555564d2e80 <haltdlg>) at ../src/gui-sdl/sdlgui.c:224
224             dlg[0].x = (pSdlGuiScrn->w/sdlgui_fontwidth-dlg[0].w)/2;
(gdb) bt
#0  0x0000555555fcf152 in SDLGui_CenterDlg (dlg=dlg@entry=0x5555564d2e80 <haltdlg>) at ../src/gui-sdl/sdlgui.c:224
#1  0x0000555555fccdae in Dialog_HaltDlg () at ../src/gui-sdl/dlgHalt.c:75
#2  0x00005555558ebc9d in cpu_halt (id=2) at ../src/cpu/newcpu.c:6273
#3  Exception_ce000 (nr=2) at ../src/cpu/newcpu.c:3258
#4  ExceptionX (nr=nr@entry=2, address=address@entry=4294967295) at ../src/cpu/newcpu.c:4088
#5  0x00005555558ecf69 in Exception (nr=nr@entry=2) at ../src/cpu/newcpu.c:4125
#6  0x00005555558ed8c9 in bus_error () at ../src/cpu/newcpu.c:4135
#7  0x00005555558ef000 in m68k_run_1_ce () at ../src/cpu/newcpu.c:5808
#8  0x00005555558ee143 in m68k_go (may_quit=may_quit@entry=1) at ../src/cpu/newcpu.c:7640
#9  0x000055555589d814 in M68000_Start () at ../src/m68000.c:298
#10 0x000055555589eb19 in main (argc=1, argv=<optimized out>) at ../src/main.c:946
(gdb) p pSdlGuiScrn
$1 = (SDL_Surface *) 0x0

I ran into this when trying to use the TOS 2.07 Sparrow ROM with a MegaSTE configuration on the current Mercurial tree.

Attached patch ensures we do SDLGui_SetScreen before SDLGui_CenterDlg in Dialog_HaltDlg, which makes the dialog appear as intended.[1]

That said, any news on getting TOS 2.07 running? Just curious...

- Steven

[1] https://i.imgur.com/mF2M8Jl.png
From cb921b68abe1844d31e49ec2024803242e0f852f Mon Sep 17 00:00:00 2001
From: Steven Noonan <steven@xxxxxxxxxxxxxx>
Date: Sat, 11 Aug 2018 06:06:41 -0700
Subject: [PATCH] Dialog_HaltDlg: ensure SDLGui screen is set before centering
 dialog

Otherwise we dereference a null pointer in SDLGui_CenterDlg.

Signed-off-by: Steven Noonan <steven@xxxxxxxxxxxxxx>
---
 src/gui-sdl/dlgHalt.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/gui-sdl/dlgHalt.c b/src/gui-sdl/dlgHalt.c
index 4aca2d60..0711f28f 100644
--- a/src/gui-sdl/dlgHalt.c
+++ b/src/gui-sdl/dlgHalt.c
@@ -72,6 +72,9 @@ void Dialog_HaltDlg(void)
 		return;
 	}
 
+	if (SDLGui_SetScreen(sdlscrn))
+		return;
+
 	SDLGui_CenterDlg(haltdlg);
 	switch (SDLGui_DoDialog(haltdlg, NULL, false)) {
 
-- 
2.17.0.582.gccdcbd54c4



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/