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
This commit is contained in:
Jiří Klimeš 2014-07-24 14:10:55 +02:00
parent 1c7e3d85fc
commit 93f7fa96d6

View file

@ -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 */