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 405d198e7c)
This commit is contained in:
Jiří Klimeš 2014-12-12 14:59:28 +01:00 committed by Thomas Haller
parent 34c6e5cdbe
commit 61f4dd5f60

View file

@ -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);