From db48c307944a9a18877236bdf9e9b778875f38ed Mon Sep 17 00:00:00 2001 From: nobu Date: Sun, 13 Dec 2015 09:28:51 +0000 Subject: psych_emitter.c: check tags range * ext/psych/psych_emitter.c (start_document): should not exceed tags array range. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53079 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/psych/psych_emitter.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'ext/psych/psych_emitter.c') diff --git a/ext/psych/psych_emitter.c b/ext/psych/psych_emitter.c index 078ae2b680..371c285183 100644 --- a/ext/psych/psych_emitter.c +++ b/ext/psych/psych_emitter.c @@ -167,16 +167,18 @@ static VALUE start_document(VALUE self, VALUE version, VALUE tags, VALUE imp) if(RTEST(tags)) { long i = 0; + long len; #ifdef HAVE_RUBY_ENCODING_H rb_encoding * encoding = rb_utf8_encoding(); #endif Check_Type(tags, T_ARRAY); - head = xcalloc((size_t)RARRAY_LEN(tags), sizeof(yaml_tag_directive_t)); + len = RARRAY_LEN(tags); + head = xcalloc((size_t)len, sizeof(yaml_tag_directive_t)); tail = head; - for(i = 0; i < RARRAY_LEN(tags); i++) { + for(i = 0; i < len && i < RARRAY_LEN(tags); i++) { VALUE tuple = RARRAY_AREF(tags, i); VALUE name; VALUE value; -- cgit v1.2.3