From fb4de0013a6d7d93f81dc2da7c2a50ead87dc767 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Mon, 6 Mar 2023 11:58:28 +0100 Subject: [PATCH] core: fix crash when reloading global dns configuration When reloading the configuration and there is a global DNS configuration without domains, NM crashes in global_dns_equal() because `old->domains` and `new->domains` are both NULL. Fix that. Thread 1 "NetworkManager" received signal SIGTRAP, Trace/breakpoint trap. 0 g_logv (log_domain=0x7fe81a2110be "GLib", log_level=G_LOG_LEVEL_CRITICAL, format=, args=) at ../glib/gmessages.c:1433 1 g_log (log_domain=, log_level=, format=) at ../glib/gmessages.c:1471 2 g_hash_table_size (hash_table=) at ../glib/ghash.c:2183 3 g_hash_table_size (hash_table=) at ../glib/ghash.c:2181 4 global_dns_equal (new=0xecc540, old=0xe618e0) at ../src/core/nm-config-data.c:1466 5 nm_config_data_diff (old_data=old_data@entry=0xe60020, new_data=new_data@entry=0xe606a0) at ../src/core/nm-config-data.c:1946 6 _set_config_data (self=0xe45810, new_data=0xe606a0, reload_flags=NM_CONFIG_CHANGE_CAUSE_SIGHUP) at ../src/core/nm-config.c:2923 7 nm_config_reload (self=0xe45810, reload_flags=NM_CONFIG_CHANGE_CAUSE_SIGHUP, emit_warnings=emit_warnings@entry=1) at ../src/core/nm-config.c:2875 8 nm_main_config_reload (signal=) at ../src/core/main.c:141 9 sighup_handler (user_data=) at ../src/core/main-utils.c:26 10 g_main_dispatch (context=0xe619e0) at ../glib/gmain.c:3444 11 g_main_context_dispatch (context=0xe619e0) at ../glib/gmain.c:4162 12 g_main_context_iterate.constprop.0 (context=0xe619e0, block=1, dispatch=1, self=) at ../glib/gmain.c:4238 13 g_main_loop_run (loop=0xe5e310) at ../glib/gmain.c:4438 14 main (argc=, argv=) at ../src/core/main.c:515 Fixes: 1f0d1d78d2a2 ('dns-manager: always apply options from [global-dns]') (cherry picked from commit ba4a9ea79a7568f52337813e61ce1171c3aa7dd2) --- src/core/nm-config-data.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/core/nm-config-data.c b/src/core/nm-config-data.c index c6ab998f94..ff44bc46b3 100644 --- a/src/core/nm-config-data.c +++ b/src/core/nm-config-data.c @@ -1463,21 +1463,23 @@ global_dns_equal(NMGlobalDnsConfig *old, NMGlobalDnsConfig *new) if ((!old->domains || !new->domains) && old->domains != new->domains) return FALSE; - if (g_hash_table_size(old->domains) != g_hash_table_size(new->domains)) + if (nm_g_hash_table_size(old->domains) != nm_g_hash_table_size(new->domains)) return FALSE; - g_hash_table_iter_init(&iter, old->domains); - while (g_hash_table_iter_next(&iter, &key, &value_old)) { - value_new = g_hash_table_lookup(new->domains, key); - if (!value_new) - return FALSE; + if (old->domains) { + g_hash_table_iter_init(&iter, old->domains); + while (g_hash_table_iter_next(&iter, &key, &value_old)) { + value_new = g_hash_table_lookup(new->domains, key); + if (!value_new) + return FALSE; - domain_old = value_old; - domain_new = value_new; + domain_old = value_old; + domain_new = value_new; - if (!nm_strv_equal(domain_old->options, domain_new->options) - || !nm_strv_equal(domain_old->servers, domain_new->servers)) - return FALSE; + if (!nm_strv_equal(domain_old->options, domain_new->options) + || !nm_strv_equal(domain_old->servers, domain_new->servers)) + return FALSE; + } } return TRUE;