summaryrefslogtreecommitdiff
path: root/ext/psych/psych_emitter.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-13 09:28:51 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-13 09:28:51 +0000
commitdb48c307944a9a18877236bdf9e9b778875f38ed (patch)
treee48512c803a3747f08e744aa1a8d946711300d17 /ext/psych/psych_emitter.c
parentcc0313436160b735a3d41361cb5e3eeb10fcbdad (diff)
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
Diffstat (limited to 'ext/psych/psych_emitter.c')
-rw-r--r--ext/psych/psych_emitter.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/ext/psych/psych_emitter.c b/ext/psych/psych_emitter.c
index 078ae2b..371c285 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;