[#25936] [Bug:1.9] [rubygems] $LOAD_PATH includes bin directory — Nobuyoshi Nakada <nobu@...>

Hi,

10 messages 2009/10/05

[#25943] Disabling tainting — Tony Arcieri <tony@...>

Would it make sense to have a flag passed to the interpreter on startup that

16 messages 2009/10/05

[#26028] [Bug #2189] Math.atanh(1) & Math.atanh(-1) should not raise an error — Marc-Andre Lafortune <redmine@...>

Bug #2189: Math.atanh(1) & Math.atanh(-1) should not raise an error

14 messages 2009/10/10

[#26222] [Bug #2250] IO::for_fd() objects' finalization dangerously closes underlying fds — Mike Pomraning <redmine@...>

Bug #2250: IO::for_fd() objects' finalization dangerously closes underlying fds

11 messages 2009/10/22

[#26244] [Bug #2258] Kernel#require inside rb_require() inside rb_protect() inside SysV context fails — Suraj Kurapati <redmine@...>

Bug #2258: Kernel#require inside rb_require() inside rb_protect() inside SysV context fails

24 messages 2009/10/22

[#26361] [Feature #2294] [PATCH] ruby_bind_stack() to embed Ruby in coroutine — Suraj Kurapati <redmine@...>

Feature #2294: [PATCH] ruby_bind_stack() to embed Ruby in coroutine

42 messages 2009/10/27

[#26371] [Bug #2295] segmentation faults — tomer doron <redmine@...>

Bug #2295: segmentation faults

16 messages 2009/10/27

[ruby-core:26228] Re: [Bug #2250] IO::for_fd() objects' finalization dangerously closes underlying fds

From: Nobuyoshi Nakada <nobu@...>
Date: 2009-10-22 08:58:08 UTC
List: ruby-core #26228
Hi,

At Thu, 22 Oct 2009 12:43:37 +0900,
Mike Pomraning wrote in [ruby-core:26222]:
> 4. Why this is very bad:
> 
> In practice, fds passed to for_fd() may be exposed by
> extension modules, which modules are responsible for the
> cleanup of the file descriptor.  Thus, close(2)ing upon
> finalization may rudely and dangerously close a file
> descriptor already closed and reassigned to some unrelated
> bit of code, causing baffling, "action at a distance"
> failures.

IO.for_fd is often dangerous.  Basically, such extension
libraries should expose IO instances, but not file descriptors.

This is a patch to add :autoclose option to IO.for_fd and
IO.new.


Index: io.c
===================================================================
--- io.c	(revision 25430)
+++ io.c	(working copy)
@@ -129,5 +129,5 @@ static VALUE argf;
 static ID id_write, id_read, id_getc, id_flush, id_readpartial;
 static VALUE sym_mode, sym_perm, sym_extenc, sym_intenc, sym_encoding, sym_open_args;
-static VALUE sym_textmode, sym_binmode;
+static VALUE sym_textmode, sym_binmode, sym_autoclose;
 
 struct timeval rb_time_interval(VALUE);
@@ -4296,4 +4296,7 @@ extract_binmode(VALUE opthash, int *fmod
 	if ((*fmode & FMODE_BINMODE) && (*fmode & FMODE_TEXTMODE))
 	    rb_raise(rb_eArgError, "both textmode and binmode specified");
+	v = rb_hash_aref(opthash, sym_autoclose);
+	if (v == Qfalse)
+	    *fmode |= FMODE_PREP;
     }
 }
@@ -9936,3 +9939,4 @@ Init_IO(void)
     sym_textmode = ID2SYM(rb_intern("textmode"));
     sym_binmode = ID2SYM(rb_intern("binmode"));
+    sym_autoclose = ID2SYM(rb_intern("autoclose"));
 }


-- 
Nobu Nakada

In This Thread