Skip to content

Commit

Permalink
* ruby.c (load_file_internal): bail out if the script is a directory.
Browse files Browse the repository at this point in the history
  [Feature ruby#2408][ruby-core:26925]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35131 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nobu committed Mar 26, 2012
1 parent 8a57e0b commit 764d547
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
Mon Mar 26 11:41:01 2012 Nobuyoshi Nakada <[email protected]>
Mon Mar 26 11:46:01 2012 Nobuyoshi Nakada <[email protected]>

* ruby.c (load_file_internal): bail out if the script is a directory.
[Feature #2408][ruby-core:26925]

* win32/win32.c (rb_w32_open, rb_w32_wopen): check if the file is a
directory when access denied, to set errno to EISDIR.
Expand Down
9 changes: 9 additions & 0 deletions ruby.c
Original file line number Diff line number Diff line change
Expand Up @@ -1524,9 +1524,18 @@ load_file_internal(VALUE arg)
}
#endif
if ((fd = rb_cloexec_open(fname, mode, 0)) < 0) {
load_failed:
rb_load_fail(fname_v, strerror(errno));
}
rb_update_max_fd(fd);
{
struct stat st;
if (fstat(fd, &st) != 0) goto load_failed;
if (S_ISDIR(st.st_mode)) {
errno = EISDIR;
goto load_failed;
}
}

f = rb_io_fdopen(fd, mode, fname);
}
Expand Down
5 changes: 5 additions & 0 deletions test/ruby/test_rubyoptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -553,4 +553,9 @@ def test_unmatching_glob
assert_in_out_err(["-C", dir, a], "", [], /LoadError/, bug3851)
end
end

def test_script_is_directory
feature2408 = '[ruby-core:26925]'
assert_in_out_err(%w[.], "", [], /Is a directory -- \./, feature2408)
end
end

0 comments on commit 764d547

Please sign in to comment.