[前][次][番号順一覧][スレッド一覧]

ruby-changes:28873

From: mame <ko1@a...>
Date: Sat, 25 May 2013 18:32:58 +0900 (JST)
Subject: [ruby-changes:28873] mame:r40925 (trunk): * dir.c (bracket): fix copy-paste error. When the first and last

mame	2013-05-25 18:32:47 +0900 (Sat, 25 May 2013)

  New Revision: 40925

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=40925

  Log:
    * dir.c (bracket): fix copy-paste error.  When the first and last
      characters of fnmatch range have different length, fnmatch may
      have wrongly matched a path that does not really match.
      Coverity Scan found this bug.

  Modified files:
    trunk/ChangeLog
    trunk/dir.c
    trunk/test/ruby/test_fnmatch.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 40924)
+++ ChangeLog	(revision 40925)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat May 25 18:08:06 2013  Yusuke Endoh  <mame@t...>
+
+	* dir.c (bracket): fix copy-paste error.  When the first and last
+	  characters of fnmatch range have different length, fnmatch may
+	  have wrongly matched a path that does not really match.
+	  Coverity Scan found this bug.
+
 Sat May 25 17:06:25 2013  Koichi Sasada  <ko1@a...>
 
 	* gc.c (after_gc_sweep): reduce full GC timing.
Index: dir.c
===================================================================
--- dir.c	(revision 40924)
+++ dir.c	(revision 40925)
@@ -178,7 +178,7 @@ bracket( https://github.com/ruby/ruby/blob/trunk/dir.c#L178
 	    p = t2 + (r2 = rb_enc_mbclen(t2, pend, enc));
 	    if (ok) continue;
 	    if ((r <= (send-s) && memcmp(t1, s, r) == 0) ||
-		(r2 <= (send-s) && memcmp(t2, s, r) == 0)) {
+		(r2 <= (send-s) && memcmp(t2, s, r2) == 0)) {
 		ok = 1;
 		continue;
 	    }
Index: test/ruby/test_fnmatch.rb
===================================================================
--- test/ruby/test_fnmatch.rb	(revision 40924)
+++ test/ruby/test_fnmatch.rb	(revision 40925)
@@ -124,4 +124,9 @@ class TestFnmatch < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_fnmatch.rb#L124
       assert_file.fnmatch("{*,#{pattern_eucjp}}", path, File::FNM_EXTGLOB)
     end
   end
+
+  def test_unicode
+    assert_file.fnmatch("[a-\u3042]*", "\u3042")
+    assert_file.not_fnmatch("[a-\u3042]*", "\u3043")
+  end
 end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]