Source: ruby1.9.1
Version: 1.9.3.194-5
Severity: important
Tags: patch
User: debian-...@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 9e6ba76df9125b9066f691ae30734b35723dedc3 Mon Sep 17 00:00:00 2001
From: Guillem Jover <guil...@hadrons.org>
Date: Tue, 18 Dec 2012 22:50:14 +0100
Subject: [PATCH] ruby1.9.1: 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.
---
 lib/drb/unix.rb      | 2 +-
 lib/webrick/utils.rb | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/drb/unix.rb b/lib/drb/unix.rb
index 549ff8c..6de5052 100644
--- a/lib/drb/unix.rb
+++ b/lib/drb/unix.rb
@@ -100,7 +100,7 @@ module DRb
     end
 
     def set_sockopt(soc)
-      soc.fcntl(Fcntl::F_SETFL, Fcntl::FD_CLOEXEC) if defined? Fcntl::FD_CLOEXEC
+      soc.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) if defined? Fcntl::FD_CLOEXEC
     end
   end
 
diff --git a/lib/webrick/utils.rb b/lib/webrick/utils.rb
index 983ac9f..157c530 100644
--- a/lib/webrick/utils.rb
+++ b/lib/webrick/utils.rb
@@ -33,7 +33,7 @@ module WEBrick
     # Sets the close on exec flag for +io+
     def set_close_on_exec(io)
       if defined?(Fcntl::FD_CLOEXEC)
-        io.fcntl(Fcntl::FD_CLOEXEC, 1)
+        io.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
       end
     end
     module_function :set_close_on_exec
-- 
1.8.1.rc0

Reply via email to