From 2597bc6f58e76ba4cd75664b6e8a5f3aa039c8ad Mon Sep 17 00:00:00 2001
From: Guillem Jover <guillem@hadrons.org>
Date: Tue, 18 Dec 2012 17:45:04 +0100
Subject: [PATCH] freeradius: Set FD_CLOEXEC correctly using F_SETFD not
 F_SETFL

Using that value on F_SETFL is just wrong, and might make the call fail
on some systems, as it's requesting to set an undetermined flag. For
example on GNU/* FD_CLOEXEC has value 1, which matches with O_WRONLY.

This might cause the code to at least leak file descriptors, and at worst
to terminate execution.
---
 src/main/event.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/main/event.c b/src/main/event.c
index 5090747..6802d1a 100644
--- a/src/main/event.c
+++ b/src/main/event.c
@@ -3600,12 +3600,14 @@ int radius_event_init(CONF_SECTION *cs, int spawn_flag)
 		       strerror(errno));
 		exit(1);
 	}
-	if (fcntl(self_pipe[0], F_SETFL, O_NONBLOCK | FD_CLOEXEC) < 0) {
+	if (fcntl(self_pipe[0], F_SETFL, O_NONBLOCK) < 0 ||
+	    fcntl(self_pipe[0], F_SETFD, FD_CLOEXEC) < 0) {
 		radlog(L_ERR, "radiusd: Error setting internal flags: %s",
 		       strerror(errno));
 		exit(1);
 	}
-	if (fcntl(self_pipe[1], F_SETFL, O_NONBLOCK | FD_CLOEXEC) < 0) {
+	if (fcntl(self_pipe[1], F_SETFL, O_NONBLOCK) < 0 ||
+	    fcntl(self_pipe[1], F_SETFD, FD_CLOEXEC) < 0) {
 		radlog(L_ERR, "radiusd: Error setting internal flags: %s",
 		       strerror(errno));
 		exit(1);
-- 
1.8.1.rc0

