Source: ruby1.8 Version: 1.8.7.358-6 Severity: important Tags: patch User: [email protected] 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 cd3a656a9c0b3f49e76e15d04ed1a5912b4b37ba Mon Sep 17 00:00:00 2001 From: Guillem Jover <[email protected]> Date: Tue, 18 Dec 2012 18:40:22 +0100 Subject: [PATCH] ruby1.8: 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 57feed8..90ca292 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 cf9da6f..1c29ef5 100644 --- a/lib/webrick/utils.rb +++ b/lib/webrick/utils.rb @@ -29,7 +29,7 @@ module WEBrick 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

