From 644e245c0b5abd5aaeba5ec0e2bd0ab6290665d1 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Fri, 13 Jan 2012 16:42:58 -0600 Subject: [PATCH] keyfile: crash less if conf_file is NULL If for some reason we have no config file, don't segfault. --- src/settings/plugins/keyfile/plugin.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/settings/plugins/keyfile/plugin.c b/src/settings/plugins/keyfile/plugin.c index 0f2a65262b..d53907a9f7 100644 --- a/src/settings/plugins/keyfile/plugin.c +++ b/src/settings/plugins/keyfile/plugin.c @@ -351,13 +351,15 @@ setup_monitoring (NMSystemConfigInterface *config) priv->monitor = monitor; } - file = g_file_new_for_path (priv->conf_file); - monitor = g_file_monitor_file (file, G_FILE_MONITOR_NONE, NULL, NULL); - g_object_unref (file); + if (priv->conf_file) { + file = g_file_new_for_path (priv->conf_file); + monitor = g_file_monitor_file (file, G_FILE_MONITOR_NONE, NULL, NULL); + g_object_unref (file); - if (monitor) { - priv->conf_file_monitor_id = g_signal_connect (monitor, "changed", G_CALLBACK (conf_file_changed), config); - priv->conf_file_monitor = monitor; + if (monitor) { + priv->conf_file_monitor_id = g_signal_connect (monitor, "changed", G_CALLBACK (conf_file_changed), config); + priv->conf_file_monitor = monitor; + } } } @@ -407,6 +409,9 @@ get_unmanaged_specs (NMSystemConfigInterface *config) GSList *specs = NULL; GError *error = NULL; + if (!priv->conf_file) + return NULL; + key_file = g_key_file_new (); if (g_key_file_load_from_file (key_file, priv->conf_file, G_KEY_FILE_NONE, &error)) { char *str; @@ -457,6 +462,9 @@ plugin_get_hostname (SCPluginKeyfile *plugin) char *hostname = NULL; GError *error = NULL; + if (!priv->conf_file) + return NULL; + key_file = g_key_file_new (); if (g_key_file_load_from_file (key_file, priv->conf_file, G_KEY_FILE_NONE, &error)) hostname = g_key_file_get_value (key_file, "keyfile", "hostname", NULL); @@ -478,6 +486,11 @@ plugin_set_hostname (SCPluginKeyfile *plugin, const char *hostname) GError *error = NULL; gboolean result = FALSE; + if (!priv->conf_file) { + g_warning ("Error saving hostname: no config file"); + return FALSE; + } + key_file = g_key_file_new (); if (g_key_file_load_from_file (key_file, priv->conf_file, G_KEY_FILE_NONE, &error)) { char *data;