summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJiří Klimeš <jklimes@redhat.com>2014-12-12 14:59:28 +0100
committerJiří Klimeš <jklimes@redhat.com>2014-12-15 16:25:11 +0100
commit405d198e7ce40a118479dc57b731fe34cf5b62d3 (patch)
tree72e06dcf2d065ee742c0a0a192aa7ca71bf1797b
parent4da19b89815cbf6e063e39bc33c04fe4b3f789df (diff)
downloadNetworkManager-405d198e7ce40a118479dc57b731fe34cf5b62d3.tar.gz
ifcfg-rh: coverity complained about not checking stat() return value
Error: CHECKED_RETURN (CWE-252): [#def21] NetworkManager-0.9.11.0/src/settings/plugins/ifcfg-rh/plugin.c:676: check_return: Calling "stat("/etc/hostname", &file_stat)" without checking return value. This library function may fail and return an error code. [Note: The source code implementation of the function has been overridden by a builtin model.]
-rw-r--r--src/settings/plugins/ifcfg-rh/plugin.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/settings/plugins/ifcfg-rh/plugin.c b/src/settings/plugins/ifcfg-rh/plugin.c
index 2f47845276..2dced56b49 100644
--- a/src/settings/plugins/ifcfg-rh/plugin.c
+++ b/src/settings/plugins/ifcfg-rh/plugin.c
@@ -671,10 +671,12 @@ plugin_set_hostname (SCPluginIfcfg *plugin, const char *hostname)
#if HAVE_SELINUX
security_context_t se_ctx_prev = NULL, se_ctx = NULL;
struct stat file_stat = { .st_mode = 0 };
+ mode_t st_mode = 0;
/* Get default context for HOSTNAME_FILE and set it for fscreate */
- stat (HOSTNAME_FILE, &file_stat);
- matchpathcon (HOSTNAME_FILE, file_stat.st_mode, &se_ctx);
+ if (stat (HOSTNAME_FILE, &file_stat) == 0)
+ st_mode = file_stat.st_mode;
+ matchpathcon (HOSTNAME_FILE, st_mode, &se_ctx);
matchpathcon_fini ();
getfscreatecon (&se_ctx_prev);
setfscreatecon (se_ctx);