Blob Blame History Raw
autofs-5.0.7 - fix fcntl return check

From: Ian Kent <raven@themaw.net>

When checking for FD_CLOEXEC support the return of the fcntl(2) call to
get the file descriptor flags is not checked which could result in an
incorrect result.
---
 include/automount.h |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/automount.h b/include/automount.h
index e72fa0d..6ced842 100644
--- a/include/automount.h
+++ b/include/automount.h
@@ -547,7 +547,8 @@ static inline void check_cloexec(int fd)
 {
 	if (cloexec_works == 0) {
 		int fl = fcntl(fd, F_GETFD);
-		cloexec_works = (fl & FD_CLOEXEC) ? 1 : -1;
+		if (fl != -1)
+			cloexec_works = (fl & FD_CLOEXEC) ? 1 : -1;
 	}
 	if (cloexec_works > 0)
 		return;