]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
charon: Explicitly check return value of fileno()
authorTobias Brunner <tobias@strongswan.org>
Wed, 15 Nov 2017 13:35:42 +0000 (14:35 +0100)
committerTobias Brunner <tobias@strongswan.org>
Wed, 15 Nov 2017 13:37:43 +0000 (14:37 +0100)
This is mainly for Coverity because fchown() can't take a negative
value, which the -1 check implies is possible.

src/charon-tkm/src/charon-tkm.c
src/charon/charon.c

index 1941e740704a9f9011d0e307989c9c044f62b7bc..7f014237a40a476c2fe11f43aacb862f7ead2a45 100644 (file)
@@ -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));
index 5d866ee0dbbb628680b8c4bb34ae86957ae0bbe8..f23717034f3986afba5c6fbc3c134ee5bceae371 100644 (file)
@@ -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));