From ae5e2fe5e5c472a54fe3a1526a7ae443ec18d035 Mon Sep 17 00:00:00 2001 From: Ailin Nemui Date: Thu, 31 Dec 2020 17:50:40 +0100 Subject: [PATCH 1/2] properly ignore empty lines and comments in servers and channels config fixes #1242 --- src/core/channels-setup.c | 4 ++++ src/core/servers-setup.c | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/core/channels-setup.c b/src/core/channels-setup.c index 55b4533e..cd323a84 100644 --- a/src/core/channels-setup.c +++ b/src/core/channels-setup.c @@ -34,6 +34,10 @@ static int compare_channel_setup (CONFIG_NODE *node, CHANNEL_SETUP_REC *channel) { char *name, *chatnet; + /* skip comment nodes */ + if (node->type == NODE_TYPE_COMMENT) + return -1; + name = config_node_get_str(node, "name", NULL); chatnet = config_node_get_str(node, "chatnet", NULL); diff --git a/src/core/servers-setup.c b/src/core/servers-setup.c index 8662b30c..6e4e238a 100644 --- a/src/core/servers-setup.c +++ b/src/core/servers-setup.c @@ -472,6 +472,10 @@ static int compare_server_setup (CONFIG_NODE *node, SERVER_SETUP_REC *server) char *address, *chatnet; int port; + /* skip comment nodes */ + if (node->type == NODE_TYPE_COMMENT) + return -1; + address = config_node_get_str(node, "address", NULL); chatnet = config_node_get_str(node, "chatnet", NULL); port = config_node_get_int(node, "port", 0); From 16b1d587036d4becc71bfeec202f83bed1362884 Mon Sep 17 00:00:00 2001 From: Ailin Nemui Date: Thu, 7 Jan 2021 09:12:17 +0100 Subject: [PATCH 2/2] Abort Irssi on wrong entries in the channels or servers config --- src/core/channels-setup.c | 13 +++++++++++-- src/core/servers-setup.c | 13 +++++++++++-- src/fe-text/irssi.c | 25 ++++++++++++++++++++----- 3 files changed, 42 insertions(+), 9 deletions(-) diff --git a/src/core/channels-setup.c b/src/core/channels-setup.c index cd323a84..c72f057c 100644 --- a/src/core/channels-setup.c +++ b/src/core/channels-setup.c @@ -207,9 +207,18 @@ static void channels_read_config(void) /* Read channels */ node = iconfig_node_traverse("channels", FALSE); if (node != NULL) { + int i = 0; tmp = config_node_first(node->value); - for (; tmp != NULL; tmp = config_node_next(tmp)) - channel_setup_read(tmp->data); + for (; tmp != NULL; tmp = config_node_next(tmp), i++) { + node = tmp->data; + if (node->type != NODE_TYPE_BLOCK) { + g_critical("Expected block node at `channels[%d]' was of %s type. " + "Corrupt config?", + i, node->type == NODE_TYPE_LIST ? "list" : "scalar"); + } else { + channel_setup_read(node); + } + } } } diff --git a/src/core/servers-setup.c b/src/core/servers-setup.c index 6e4e238a..43653c43 100644 --- a/src/core/servers-setup.c +++ b/src/core/servers-setup.c @@ -625,9 +625,18 @@ static void read_servers(void) /* Read servers */ node = iconfig_node_traverse("servers", FALSE); if (node != NULL) { + int i = 0; tmp = config_node_first(node->value); - for (; tmp != NULL; tmp = config_node_next(tmp)) - server_setup_read(tmp->data); + for (; tmp != NULL; tmp = config_node_next(tmp), i++) { + node = tmp->data; + if (node->type != NODE_TYPE_BLOCK) { + g_critical("Expected block node at `servers[%d]' was of %s type. " + "Corrupt config?", + i, node->type == NODE_TYPE_LIST ? "list" : "scalar"); + } else { + server_setup_read(node); + } + } } } diff --git a/src/fe-text/irssi.c b/src/fe-text/irssi.c index 1b891522..5c20eb37 100644 --- a/src/fe-text/irssi.c +++ b/src/fe-text/irssi.c @@ -162,6 +162,16 @@ static void textui_init(void) signal_add_last("gui exit", (SIGNAL_FUNC) sig_exit); } +static int critical_fatal_section_begin(void) +{ + return g_log_set_always_fatal(G_LOG_FATAL_MASK | G_LOG_LEVEL_CRITICAL); +} + +static void critical_fatal_section_end(int loglev) +{ + g_log_set_always_fatal(loglev); +} + static void textui_finish_init(void) { int loglev; @@ -182,10 +192,9 @@ static void textui_finish_init(void) mainwindows_layout_init(); gui_windows_init(); /* Temporarily raise the fatal level to abort on config errors. */ - loglev = g_log_set_always_fatal(G_LOG_FATAL_MASK | G_LOG_LEVEL_CRITICAL); + loglev = critical_fatal_section_begin(); statusbar_init(); - g_log_set_always_fatal(loglev); - term_refresh_thaw(); + critical_fatal_section_end(loglev); settings_check(); @@ -202,7 +211,12 @@ static void textui_finish_init(void) dirty_check(); + /* Temporarily raise the fatal level to abort on config errors. */ + loglev = critical_fatal_section_begin(); fe_common_core_finish_init(); + critical_fatal_section_end(loglev); + term_refresh_thaw(); + signal_emit("irssi init finished", 0); statusbar_redraw(NULL, TRUE); @@ -329,7 +343,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); /* Temporarily raise the fatal level to abort on config errors. */ - loglev = g_log_set_always_fatal(G_LOG_FATAL_MASK | G_LOG_LEVEL_CRITICAL); + loglev = critical_fatal_section_begin(); textui_init(); if (!term_init()) { @@ -337,7 +351,8 @@ int main(int argc, char **argv) return 1; } - g_log_set_always_fatal(loglev); + critical_fatal_section_end(loglev); + textui_finish_init(); main_loop = g_main_loop_new(NULL, TRUE);