aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--io.c2
2 files changed, 6 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 788752ec6c..bcbd4c9f52 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Thu Dec 25 17:06:13 2008 Tanaka Akira <akr@fsij.org>
+
+ * io.c (rb_io_initialize): check fd validity. [ruby-dev:36646]
+
Thu Dec 25 16:23:31 2008 Tanaka Akira <akr@fsij.org>
* io.c (flush_before_seek): check io_fflush result.
diff --git a/io.c b/io.c
index a8a7554c95..2ebf6de273 100644
--- a/io.c
+++ b/io.c
@@ -5928,6 +5928,7 @@ rb_io_initialize(int argc, VALUE *argv, VALUE io)
int fd, fmode, oflags = O_RDONLY;
convconfig_t convconfig;
VALUE opt;
+ struct stat st;
rb_secure(4);
@@ -5936,6 +5937,7 @@ rb_io_initialize(int argc, VALUE *argv, VALUE io)
rb_io_extract_modeenc(&vmode, 0, opt, &oflags, &fmode, &convconfig);
fd = NUM2INT(fnum);
+ if (fstat(fd, &st) == -1) rb_sys_fail(0);
UPDATE_MAXFD(fd);
if (NIL_P(vmode)) {
#if defined(HAVE_FCNTL) && defined(F_GETFL)