Skip to content

Commit 36bf7f4

Browse files
committed
asn1: fix possible segfault in OpenSSL::ASN1::Constructive#each
Don't blindy assume that the value which can be modified from Ruby code is always an Array, and just call its #each method.
1 parent fd0c434 commit 36bf7f4

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

ext/openssl/ossl_asn1.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ VALUE cASN1Sequence, cASN1Set; /* CONSTRUCTIVE */
182182
static VALUE sym_IMPLICIT, sym_EXPLICIT;
183183
static VALUE sym_UNIVERSAL, sym_APPLICATION, sym_CONTEXT_SPECIFIC, sym_PRIVATE;
184184
static ID sivVALUE, sivTAG, sivTAG_CLASS, sivTAGGING, sivINFINITE_LENGTH, sivUNUSED_BITS;
185+
static ID id_each;
185186

186187
/*
187188
* Ruby to ASN1 converters
@@ -696,7 +697,7 @@ static VALUE
696697
join_der(VALUE enumerable)
697698
{
698699
VALUE str = rb_str_new(0, 0);
699-
rb_block_call(enumerable, rb_intern("each"), 0, 0, join_der_i, str);
700+
rb_block_call(enumerable, id_each, 0, 0, join_der_i, str);
700701
return str;
701702
}
702703

@@ -1284,7 +1285,8 @@ ossl_asn1cons_to_der(VALUE self)
12841285
static VALUE
12851286
ossl_asn1cons_each(VALUE self)
12861287
{
1287-
rb_ary_each(ossl_asn1_get_value(self));
1288+
rb_funcall(ossl_asn1_get_value(self), id_each, 0);
1289+
12881290
return self;
12891291
}
12901292

@@ -1925,4 +1927,6 @@ do{\
19251927
rb_hash_aset(class_tag_map, cASN1UniversalString, INT2NUM(V_ASN1_UNIVERSALSTRING));
19261928
rb_hash_aset(class_tag_map, cASN1BMPString, INT2NUM(V_ASN1_BMPSTRING));
19271929
rb_global_variable(&class_tag_map);
1930+
1931+
id_each = rb_intern_const("each");
19281932
}

0 commit comments

Comments
 (0)