diff options
author | Jiří Klimeš <jklimes@redhat.com> | 2014-12-12 14:59:28 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2014-12-16 21:47:01 +0100 |
commit | 61f4dd5f60d339b8be2786c0f888227d0f53d7cc (patch) | |
tree | a2843def113e161fd09715284a35c359358ea537 | |
parent | 34c6e5cdbec3b3285a67598bac2e39c0cc3f518d (diff) | |
download | NetworkManager-61f4dd5f60d339b8be2786c0f888227d0f53d7cc.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.]
(cherry picked from commit 405d198e7ce40a118479dc57b731fe34cf5b62d3)
-rw-r--r-- | src/settings/plugins/ifcfg-rh/plugin.c | 6 |
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); |