Bug#696279: ocamlnet: Sets FD_CLOEXEC incorrectly with F_SETFL instead of F_SETFD
Source: ocamlnet
Version: 3.5.1-1
Severity: important
Tags: patch
User: debian-bsd@lists.debian.org
Usertags: fcntl-fd-cloexec
Hi!
This package contains code that tries to set the FD_CLOEXEC flag for a
file descriptor, but it does using F_SETFL instead of F_SETFD.
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.
Attached a patch fixing this.
Thanks,
Guillem
From 7c7af1cd47b577dda2f38755e367632f8a73c4b1 Mon Sep 17 00:00:00 2001
From: Guillem Jover <guillem@hadrons.org>
Date: Tue, 18 Dec 2012 18:25:47 +0100
Subject: [PATCH] ocamlnet: 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/netsys/netsys_c_poll.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/netsys/netsys_c_poll.c b/src/netsys/netsys_c_poll.c
index d9f67df..bc680e7 100644
--- a/src/netsys/netsys_c_poll.c
+++ b/src/netsys/netsys_c_poll.c
@@ -218,7 +218,7 @@ CAMLprim value netsys_create_event_aggreg(value cancelv)
#ifdef HAVE_EPOLL
fd = epoll_create(128);
if (fd == -1) uerror("epoll_create", Nothing);
- code = fcntl(fd, F_SETFL, FD_CLOEXEC);
+ code = fcntl(fd, F_SETFD, FD_CLOEXEC);
if (code == -1) {
e = errno;
close(fd);
@@ -238,7 +238,7 @@ CAMLprim value netsys_create_event_aggreg(value cancelv)
close(fd);
unix_error(e, "eventfd", Nothing);
};
- code = fcntl(cancel_fd, F_SETFL, FD_CLOEXEC);
+ code = fcntl(cancel_fd, F_SETFD, FD_CLOEXEC);
if (code == -1) {
e = errno;
close(fd);
--
1.8.1.rc0
Reply to: