|
|
f70500 |
From 85b582da9260df77669409f0859ef253712ae115 Mon Sep 17 00:00:00 2001
|
|
|
f70500 |
From: usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>
|
|
|
f70500 |
Date: Wed, 28 Mar 2018 14:27:51 +0000
|
|
|
f70500 |
Subject: [PATCH] merge revision(s) 62989:
|
|
|
f70500 |
|
|
|
f70500 |
dir.c: check NUL bytes
|
|
|
f70500 |
|
|
|
f70500 |
* dir.c (GlobPathValue): should be used in rb_push_glob only.
|
|
|
f70500 |
other methods should use FilePathValue.
|
|
|
f70500 |
https://hackerone.com/reports/302338
|
|
|
f70500 |
|
|
|
f70500 |
* dir.c (rb_push_glob): expand GlobPathValue
|
|
|
f70500 |
|
|
|
f70500 |
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@63015 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
|
|
|
f70500 |
---
|
|
|
f70500 |
dir.c | 22 ++++++++++------------
|
|
|
f70500 |
test/ruby/test_dir.rb | 4 ++++
|
|
|
f70500 |
2 files changed, 14 insertions(+), 12 deletions(-)
|
|
|
f70500 |
|
|
|
f70500 |
diff --git a/dir.c b/dir.c
|
|
|
f70500 |
index 7d61b61fdb..a65c1deeea 100644
|
|
|
f70500 |
--- a/dir.c
|
|
|
f70500 |
+++ b/dir.c
|
|
|
f70500 |
@@ -356,15 +356,6 @@ static const rb_data_type_t dir_data_type = {
|
|
|
f70500 |
|
|
|
f70500 |
static VALUE dir_close(VALUE);
|
|
|
f70500 |
|
|
|
f70500 |
-#define GlobPathValue(str, safe) \
|
|
|
f70500 |
- /* can contain null bytes as separators */ \
|
|
|
f70500 |
- (!RB_TYPE_P((str), T_STRING) ? \
|
|
|
f70500 |
- (void)FilePathValue(str) : \
|
|
|
f70500 |
- (void)(check_safe_glob((str), (safe)), \
|
|
|
f70500 |
- check_glob_encoding(str), (str)))
|
|
|
f70500 |
-#define check_safe_glob(str, safe) ((safe) ? rb_check_safe_obj(str) : (void)0)
|
|
|
f70500 |
-#define check_glob_encoding(str) rb_enc_check((str), rb_enc_from_encoding(rb_usascii_encoding()))
|
|
|
f70500 |
-
|
|
|
f70500 |
static VALUE
|
|
|
f70500 |
dir_s_alloc(VALUE klass)
|
|
|
f70500 |
{
|
|
|
f70500 |
@@ -406,7 +397,7 @@ dir_initialize(int argc, VALUE *argv, VALUE dir)
|
|
|
f70500 |
}
|
|
|
f70500 |
}
|
|
|
f70500 |
|
|
|
f70500 |
- GlobPathValue(dirname, FALSE);
|
|
|
f70500 |
+ FilePathValue(dirname);
|
|
|
f70500 |
orig = rb_str_dup_frozen(dirname);
|
|
|
f70500 |
dirname = rb_str_encode_ospath(dirname);
|
|
|
f70500 |
dirname = rb_str_dup_frozen(dirname);
|
|
|
f70500 |
@@ -1711,7 +1702,14 @@ rb_push_glob(VALUE str, int flags) /* '\0' is delimiter */
|
|
|
f70500 |
long offset = 0;
|
|
|
f70500 |
VALUE ary;
|
|
|
f70500 |
|
|
|
f70500 |
- GlobPathValue(str, TRUE);
|
|
|
f70500 |
+ /* can contain null bytes as separators */
|
|
|
f70500 |
+ if (!RB_TYPE_P((str), T_STRING)) {
|
|
|
f70500 |
+ FilePathValue(str);
|
|
|
f70500 |
+ }
|
|
|
f70500 |
+ else {
|
|
|
f70500 |
+ rb_check_safe_obj(str);
|
|
|
f70500 |
+ rb_enc_check(str, rb_enc_from_encoding(rb_usascii_encoding()));
|
|
|
f70500 |
+ }
|
|
|
f70500 |
ary = rb_ary_new();
|
|
|
f70500 |
|
|
|
f70500 |
while (offset < RSTRING_LEN(str)) {
|
|
|
f70500 |
@@ -1741,7 +1739,7 @@ dir_globs(long argc, VALUE *argv, int flags)
|
|
|
f70500 |
for (i = 0; i < argc; ++i) {
|
|
|
f70500 |
int status;
|
|
|
f70500 |
VALUE str = argv[i];
|
|
|
f70500 |
- GlobPathValue(str, TRUE);
|
|
|
f70500 |
+ FilePathValue(str);
|
|
|
f70500 |
status = push_glob(ary, str, flags);
|
|
|
f70500 |
if (status) GLOB_JUMP_TAG(status);
|
|
|
f70500 |
}
|
|
|
f70500 |
diff --git a/test/ruby/test_dir.rb b/test/ruby/test_dir.rb
|
|
|
f70500 |
index 2ad6bdefcb..7624836ff4 100644
|
|
|
f70500 |
--- a/test/ruby/test_dir.rb
|
|
|
f70500 |
+++ b/test/ruby/test_dir.rb
|
|
|
f70500 |
@@ -164,6 +164,9 @@ class TestDir < Test::Unit::TestCase
|
|
|
f70500 |
|
|
|
f70500 |
assert_equal([File.join(@root, "a")], Dir.glob(File.join(@root, 'a\\')))
|
|
|
f70500 |
assert_equal((?a..?f).map {|f| File.join(@root, f) }.sort, Dir.glob(File.join(@root, '[abc/def]')).sort)
|
|
|
f70500 |
+ assert_raise(ArgumentError) {
|
|
|
f70500 |
+ Dir.glob([[@root, File.join(@root, "*")].join("\0")])
|
|
|
f70500 |
+ }
|
|
|
f70500 |
end
|
|
|
f70500 |
|
|
|
f70500 |
def test_glob_recursive
|
|
|
f70500 |
@@ -194,6 +197,7 @@ class TestDir < Test::Unit::TestCase
|
|
|
f70500 |
|
|
|
f70500 |
def test_foreach
|
|
|
f70500 |
assert_equal(Dir.foreach(@root).to_a.sort, %w(. ..) + (?a..?z).to_a)
|
|
|
f70500 |
+ assert_raise(ArgumentError) {Dir.foreach(@root+"\0").to_a}
|
|
|
f70500 |
end
|
|
|
f70500 |
|
|
|
f70500 |
def test_dir_enc
|
|
|
f70500 |
--
|
|
|
f70500 |
2.17.1
|
|
|
f70500 |
|