diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-04-07 02:24:16 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-04-07 02:24:16 +0000 |
commit | de3f0a42d83015930a5df185a4c7e59665ec860d (patch) | |
tree | c8df1d42254ff35dfc38b1a3156c8c9878189d25 /ext/tk/tkutil | |
parent | 9cd35c22ab11dfc76cb125dc2695f922620a46e1 (diff) | |
download | ruby-de3f0a42d83015930a5df185a4c7e59665ec860d.tar.gz |
tkutil.c: fix overrun
* ext/tk/tkutil/tkutil.c (cbsubst_initialize): fix out-of-bound
access when no arguments given. `p Tk::Event.new` crashed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54509 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk/tkutil')
-rw-r--r-- | ext/tk/tkutil/tkutil.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/ext/tk/tkutil/tkutil.c b/ext/tk/tkutil/tkutil.c index 147dfa23d1..3b1d3c5ecf 100644 --- a/ext/tk/tkutil/tkutil.c +++ b/ext/tk/tkutil/tkutil.c @@ -1284,11 +1284,13 @@ cbsubst_initialize(argc, argv, self) inf = cbsubst_get_ptr(rb_obj_class(self)); - idx = 0; - for(iv_idx = 0; iv_idx < CBSUBST_TBL_MAX; iv_idx++) { - if ( inf->ivar[iv_idx] == (ID) 0 ) continue; - rb_ivar_set(self, inf->ivar[iv_idx], argv[idx++]); - if (idx >= argc) break; + if (argc > 0) { + idx = 0; + for (iv_idx = 0; iv_idx < CBSUBST_TBL_MAX; iv_idx++) { + if (inf->ivar[iv_idx] == (ID)0) continue; + rb_ivar_set(self, inf->ivar[iv_idx], argv[idx++]); + if (idx >= argc) break; + } } return self; |