[PATCH RESEND] terminal: fix crashing when terminal size is < 0

Tiago Vignatti tiago.vignatti at nokia.com
Tue Jan 11 05:01:19 PST 2011


On Mon, Jan 10, 2011 at 02:20:59PM -0500, ext Kristian H�gsberg wrote:
> On Mon, Jan 10, 2011 at 12:30 PM, Tiago Vignatti
> <tiago.vignatti at nokia.com> wrote:
> > Just skip drawing when width or height is less than zero.
> >
> > Signed-off-by: Tiago Vignatti <tiago.vignatti at nokia.com>
> > ---
> > haven't tested actually whether child windows still okay.
> 
> Still crashes here with your patch, and I was thinking that it'd be
> better to restict the minimum size to one character cell and then work
> backwards from that to find the minimum size.

you're right, Kristian. The patch I provided just fix this segfault - which I
can reproduce pretty easy when resizing in horizontal:

Program received signal SIGSEGV, Segmentation fault.
0x005a93b4 in ?? () from /lib/libc.so.6
(gdb) bt
#0  0x005a93b4 in ?? () from /lib/libc.so.6
#1  0x0804b7ce in terminal_resize (terminal=0x85eb208, width=-3, height=24)
    at terminal.c:604
#2  0x0804c25d in terminal_draw (terminal=0x85eb208) at terminal.c:841
#3  0x0804c29b in redraw_handler (window=0x86b8548, data=0x85eb208)
    at terminal.c:853
#4  0x08051742 in idle_redraw (data=0x86b8548) at window.c:1115
#5  0x00364841 in ?? () from /lib/libglib-2.0.so.0
#6  0x00366855 in g_main_context_dispatch () from /lib/libglib-2.0.so.0
#7  0x0036a668 in ?? () from /lib/libglib-2.0.so.0
#8  0x0036aba7 in g_main_loop_run () from /lib/libglib-2.0.so.0
#9  0x08052585 in display_run (d=0x805d080) at window.c:1531
#10 0x0804f171 in main (argc=1, argv=0xbffff624) at terminal.c:1931


but then we still have the other bug, with the following stack trace
happening. This happens quite a lot when I resize in the diagonal till the
terminal has no size anymore:

Program received signal SIGFPE, Arithmetic exception.
0x0804afad in terminal_get_row (terminal=0x85eb208, row=-1) at terminal.c:449
449     index = (row + terminal->start) % terminal->height;
(gdb) bt
#0  0x0804afad in terminal_get_row (terminal=0x85eb208, row=-1)
    at terminal.c:449
#1  0x0804e095 in handle_special_char (terminal=0x85eb208, c=13 '\r')
    at terminal.c:1468
#2  0x0804e2e1 in handle_char (terminal=0x85eb208, utf8=...) at
terminal.c:1541
#3  0x0804e730 in terminal_data (terminal=0x85eb208,
    data=0xbffff29c
"\r\033[K\033[A\033[A\033[A\033[A\033[A\033[A\033[A\033[A\033[A\033[A\033[A\033[A\033[A\033[A\033[A\033[A\033]0;root at ideapad:
~/wayland/wayland\aroo\rot@\r at id\rdea\rapa\rad:\r:~/\r/wa\rayl\rlan\rnd/\r/wa\rayl\rlan\rnd#\r#
\r\001", length=152) at terminal.c:1665
#4  0x0804efa0 in io_handler (source=0x885a810, condition=G_IO_IN,
    data=0x85eb208) at terminal.c:1877
#5  0x003ade5b in ?? () from /lib/libglib-2.0.so.0
#6  0x00366855 in g_main_context_dispatch () from /lib/libglib-2.0.so.0
#7  0x0036a668 in ?? () from /lib/libglib-2.0.so.0
#8  0x0036aba7 in g_main_loop_run () from /lib/libglib-2.0.so.0
#9  0x08052585 in display_run (d=0x805d080) at window.c:1531
#10 0x0804f171 in main (argc=1, argv=0xbffff624) at terminal.c:1931


and rarely I see this other one, which I guess is not related with resizing:

Program received signal SIGABRT, Aborted.
0x0012e416 in __kernel_vsyscall ()
(gdb) bt
#0  0x0012e416 in __kernel_vsyscall ()
#1  0x004c0941 in raise () from /lib/libc.so.6
#2  0x004c3e42 in abort () from /lib/libc.so.6
#3  0x00130b7b in display_handle_invalid_object (data=0x0, display=0x805d500,
    id=0) at wayland-client.c:247
#4  0x005f83ff in ffi_call_SYSV () from /usr/lib/libffi.so.5
#5  0x005f822f in ffi_call () from /usr/lib/libffi.so.5
#6  0x001328cf in wl_closure_invoke (closure=0x80615e4, target=0x805d500,
    func=0x130b38 <display_handle_invalid_object>, data=0x0)
    at connection.c:657
#7  0x00131318 in handle_event (display=0x805d500, id=1, opcode=0, size=12)
    at wayland-client.c:484
#8  0x001313db in wl_display_iterate (display=0x805d500, mask=1)
    at wayland-client.c:509
#9  0x08052637 in wl_glib_source_dispatch (base=0x8611128, callback=0,
    data=0x0) at wayland-glib.c:68
#10 0x00366855 in g_main_context_dispatch () from /lib/libglib-2.0.so.0
#11 0x0036a668 in ?? () from /lib/libglib-2.0.so.0
#12 0x0036aba7 in g_main_loop_run () from /lib/libglib-2.0.so.0
#13 0x08052585 in display_run (d=0x805d080) at window.c:1531
#14 0x0804f171 in main (argc=1, argv=0xbffff624) at terminal.c:1931


anyway, if we follow your advice and restrict the minimum size for something >
zero, I think we are okay. For instance, I saw that Gnome Terminal has a
minimum of 4 for the width and 2 for the height, and if we throttle our
demo terminal for those we fix at least those two first bugs. Here:

diff --git a/clients/terminal.c b/clients/terminal.c
index 4bfb06b..a7aba84 100644
--- a/clients/terminal.c
+++ b/clients/terminal.c
@@ -838,6 +838,9 @@ terminal_draw(struct terminal *terminal)
                (int32_t) terminal->extents.max_x_advance;
        height = (rectangle.height - 2 * terminal->margin) /
                (int32_t) terminal->extents.height;
+       if (width < 4 || height < 2)
+               return;
+
        terminal_resize(terminal, width, height);
 
        window_draw(terminal->window);


             Tiago


More information about the wayland-devel mailing list