From 311960cdaf4e884643235fe83a3970b5e1f5ba47 Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 8 Apr 2013 08:19:32 +0000 Subject: win32ole.c: check arity * ext/win32ole/win32ole.c (fole_missing): should check actual argument count before accessing. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40184 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ ext/win32ole/win32ole.c | 2 ++ test/win32ole/test_win32ole.rb | 7 +++++++ 3 files changed, 14 insertions(+) diff --git a/ChangeLog b/ChangeLog index 6bec25019a..cefe3e3a50 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Mon Apr 8 17:19:28 2013 Nobuyoshi Nakada + + * ext/win32ole/win32ole.c (fole_missing): should check actual argument + count before accessing. + Mon Apr 8 16:03:55 2013 Yuki Yugui Sonoda Fixes a build failure of ext/ripper/ripper.c on building out of place. diff --git a/ext/win32ole/win32ole.c b/ext/win32ole/win32ole.c index 5310cbfae1..37fa1c63c8 100644 --- a/ext/win32ole/win32ole.c +++ b/ext/win32ole/win32ole.c @@ -4078,6 +4078,7 @@ fole_missing(int argc, VALUE *argv, VALUE self) ID id; const char* mname; int n; + rb_check_arity(argc, 1, UNLIMITED_ARGUMENTS); id = rb_to_id(argv[0]); mname = rb_id2name(id); if(!mname) { @@ -4085,6 +4086,7 @@ fole_missing(int argc, VALUE *argv, VALUE self) } n = strlen(mname); if(mname[n-1] == '=') { + rb_check_arity(argc, 2, 2); argv[0] = rb_enc_str_new(mname, n-1, cWIN32OLE_enc); return ole_propertyput(self, argv[0], argv[1]); diff --git a/test/win32ole/test_win32ole.rb b/test/win32ole/test_win32ole.rb index 40b6a81544..5b237370b5 100644 --- a/test/win32ole/test_win32ole.rb +++ b/test/win32ole/test_win32ole.rb @@ -495,6 +495,13 @@ if defined?(WIN32OLE) def test_const_LOCALE_USER_DEFAULT assert_equal(0x0400, WIN32OLE::LOCALE_USER_DEFAULT); end + + def test_method_missing + assert_raise(ArgumentError) {@dict1.method_missing} + assert_raise(TypeError) {@dict1.method_missing(1)} + assert_raise(ArgumentError) {@dict1.method_missing("foo=")} + assert_raise(ArgumentError) {@dict1.method_missing("foo=", 1, 2)} + end end # test of subclass of WIN32OLE -- cgit v1.2.3