diff options
author | Tobias Brunner <tobias@strongswan.org> | 2017-11-15 14:35:42 +0100 |
---|---|---|
committer | Tobias Brunner <tobias@strongswan.org> | 2017-11-15 14:37:43 +0100 |
commit | 42353849cb144a5310c7153147d1624b1593ce8d (patch) | |
tree | fffee93f5978139c5735c20598f2a1a5a1511e44 | |
parent | be79839ea7f25c33bb89a605282d52a65605bb5e (diff) | |
download | strongswan-42353849cb144a5310c7153147d1624b1593ce8d.tar.bz2 strongswan-42353849cb144a5310c7153147d1624b1593ce8d.tar.xz |
charon: Explicitly check return value of fileno()
This is mainly for Coverity because fchown() can't take a negative
value, which the -1 check implies is possible.
-rw-r--r-- | src/charon-tkm/src/charon-tkm.c | 7 | ||||
-rw-r--r-- | src/charon/charon.c | 7 |
2 files changed, 12 insertions, 2 deletions
diff --git a/src/charon-tkm/src/charon-tkm.c b/src/charon-tkm/src/charon-tkm.c index 1941e7407..7f014237a 100644 --- a/src/charon-tkm/src/charon-tkm.c +++ b/src/charon-tkm/src/charon-tkm.c @@ -211,7 +211,12 @@ static bool check_pidfile() int fd; fd = fileno(pidfile); - if (fd == -1 || fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) + if (fd == -1) + { + DBG1(DBG_DMN, "unable to determine fd for '%s'", pidfile_name); + return TRUE; + } + if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) { DBG1(DBG_LIB, "setting FD_CLOEXEC for '%s' failed: %s", pidfile_name, strerror(errno)); diff --git a/src/charon/charon.c b/src/charon/charon.c index 5d866ee0d..f23717034 100644 --- a/src/charon/charon.c +++ b/src/charon/charon.c @@ -221,7 +221,12 @@ static bool check_pidfile() int fd; fd = fileno(pidfile); - if (fd == -1 || fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) + if (fd == -1) + { + DBG1(DBG_DMN, "unable to determine fd for '"PID_FILE"'"); + return TRUE; + } + if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) { DBG1(DBG_LIB, "setting FD_CLOEXEC for '"PID_FILE"' failed: %s", strerror(errno)); |