bugfix: fix coredump when resizing terminal window

In the signal handler for the signal SIGWINCH tty_term_resize, we call
tty_dpy_invalidate function. In this function, we change the screen_size
and other critical fields.

While the process is executing the function tty_dpy_flush, and another
SIGWINCH occurs, then the screen_size is changed. And tty_dpy_flush will
access invalid memory which leads to coredump.

In the signal hander of SIGWINCH, we only need to set the flag
complete_refresh.
This commit is contained in:
4g4 2026-04-29 15:27:52 +08:00 • committed by Charlie Gordon
commit 6cd79d45df
3 changed files with 4 additions and 7 deletions

2
qe.h
View file

@ -110,7 +110,7 @@ void set_write_handler(int fd, void (*cb)(void *opaque), void *opaque);
int set_pid_handler(int pid,
void (*cb)(void *opaque, int status), void *opaque);
void url_exit(void);
void url_redisplay(void);
void url_redisplay(QEditScreen *s);
void register_bottom_half(void (*cb)(void *opaque), void *opaque);
void unregister_bottom_half(void (*cb)(void *opaque), void *opaque);

6
tty.c
View file

@ -658,11 +658,7 @@ static void tty_term_resize(qe__unused__ int sig)
QEditScreen *s = tty_screen;
if (s) {
tty_dpy_invalidate(s);
//fprintf(stderr, "tty_term_resize: width=%d, height=%d\n", s->width, s->height);
url_redisplay();
url_redisplay(s);
}
}

3
unix.c
View file

@ -346,9 +346,10 @@ void url_exit(void)
}
/* asynchronous redisplay signal received */
void url_redisplay(void)
void url_redisplay(QEditScreen *s)
{
url_display_request = 1;
s->qs->complete_refresh = 1;
}
int get_clock_ms(void) {