summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2018-12-12 14:38:09 +0900
committerYusuke Endoh <mame@ruby-lang.org>2019-10-01 19:19:56 +0900
commita0a2640b398cffd351f87d3f6243103add66575b (patch)
treea8dc849fe08b67a7a54f081c2654ce2812ad42e4
parenta38fe1fbf068d05177e6e6fac2b8ec7704873e63 (diff)
Fix for wrong fnmatch patttern
* dir.c (file_s_fnmatch): ensure that pattern does not contain a NUL character. https://hackerone.com/reports/449617
-rw-r--r--dir.c2
-rw-r--r--test/ruby/test_fnmatch.rb6
2 files changed, 7 insertions, 1 deletions
diff --git a/dir.c b/dir.c
index 6d1f501927..d20cf60a7f 100644
--- a/dir.c
+++ b/dir.c
@@ -3211,7 +3211,7 @@ file_s_fnmatch(int argc, VALUE *argv, VALUE obj)
else
flags = 0;
- StringValue(pattern);
+ StringValueCStr(pattern);
FilePathStringValue(path);
if (flags & FNM_EXTGLOB) {
diff --git a/test/ruby/test_fnmatch.rb b/test/ruby/test_fnmatch.rb
index f594a00ad3..16f1076e48 100644
--- a/test/ruby/test_fnmatch.rb
+++ b/test/ruby/test_fnmatch.rb
@@ -160,4 +160,10 @@ class TestFnmatch < Test::Unit::TestCase
assert_file.fnmatch("[a-\u3042]*", "\u3042")
assert_file.not_fnmatch("[a-\u3042]*", "\u3043")
end
+
+ def test_nullchar
+ assert_raise(ArgumentError) {
+ File.fnmatch("a\0z", "a")
+ }
+ end
end