From 059cb81817cfa9d56ac4168f738836adf6dd6caa Mon Sep 17 00:00:00 2001 From: Přemysl Janouch Date: Thu, 3 Nov 2016 02:25:47 +0100 Subject: Try to fix terminfo loading It could lead to crashing the PTY under OpenBSD and ncurses. Fixed some unibiliums leaks while at it. --- driver-ti.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/driver-ti.c b/driver-ti.c index 719dc2e..46a1d8b 100644 --- a/driver-ti.c +++ b/driver-ti.c @@ -177,6 +177,7 @@ static bool load_terminfo (termo_ti_t *ti, const char *term) { const char *mouse_report_string = NULL; + bool result = false; #ifdef HAVE_UNIBILIUM unibi_term *unibi = unibi_from_term (term); @@ -191,8 +192,12 @@ load_terminfo (termo_ti_t *ti, const char *term) // Have to cast away the const. But it's OK - we know terminfo won't // really modify term int err; + TERMINAL *saved_term = set_curterm (NULL); if (setupterm ((char *) term, 1, &err) != OK) + { + set_curterm (saved_term); return false; + } for (int i = 0; strfnames[i]; i++) { @@ -227,8 +232,7 @@ load_terminfo (termo_ti_t *ti, const char *term) if (node && !insert_seq (ti, value, node)) { free (node); - // FIXME: unibi leak - return false; + goto fail; } } @@ -255,14 +259,13 @@ load_terminfo (termo_ti_t *ti, const char *term) trie_node_t *node = malloc (sizeof *node); if (!node) - return false; + goto fail; node->type = TYPE_MOUSE; if (!insert_seq (ti, mouse_report_string, node)) { free (node); - // FIXME: unibi leak - return false; + goto fail; } } @@ -305,11 +308,14 @@ load_terminfo (termo_ti_t *ti, const char *term) else ti->stop_string = NULL; + result = true; +fail: #ifdef HAVE_UNIBILIUM unibi_destroy (unibi); +#else + del_curterm (set_curterm (saved_term)); #endif - - return true; + return result; } static bool -- cgit v1.2.3-70-g09d2