From 93f7fa96d6a2b4e5da03a3d1f19b2d3ca538b7f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= Date: Thu, 24 Jul 2014 14:10:55 +0200 Subject: [PATCH] ifcfg-rh: fix a crash on setting hostname with SELinux disabled (rh #1122826) When SELinux is disabled, getfscreatecon() fails leaving se_ctx_prev undefined and then later freecon (se_ctx_prev) fails with a crash. Initializing se_ctx_prev to NULL fixes the crash. (It is fine to pass NULL context to setfscreatecon()). Testcase: 1) Enable ifcfg-rh plugin in /etc/NetworkManger/NetworkManger.conf plugins=ifcfg-rh 2) Edit /etc/sysconfig/selinux to contain SELINUX=disabled 3) Reboot 4) Set hostname via nmcli, nmtui or D-Bus SaveHostname() call 5) NM crashes https://bugzilla.redhat.com/show_bug.cgi?id=1122826 --- src/settings/plugins/ifcfg-rh/plugin.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/settings/plugins/ifcfg-rh/plugin.c b/src/settings/plugins/ifcfg-rh/plugin.c index b067c5861d..0567ba2406 100644 --- a/src/settings/plugins/ifcfg-rh/plugin.c +++ b/src/settings/plugins/ifcfg-rh/plugin.c @@ -670,7 +670,7 @@ plugin_set_hostname (SCPluginIfcfg *plugin, const char *hostname) char *hostname_eol; gboolean ret; #if HAVE_SELINUX - security_context_t se_ctx_prev, se_ctx = NULL; + security_context_t se_ctx_prev = NULL, se_ctx = NULL; struct stat file_stat = { .st_mode = 0 }; /* Get default context for HOSTNAME_FILE and set it for fscreate */