Skip to content

Commit 6dfb8df

Browse files
authored
Merge pull request #859 from rhenium/ky/asn1-decode-missing-eoc
asn1: check for missing EOC in indefinite length encoding
2 parents 201a5d3 + bc20c13 commit 6dfb8df

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

ext/openssl/ossl_asn1.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -797,10 +797,12 @@ int_ossl_asn1_decode0_cons(unsigned char **pp, long max_len, long length,
797797
*num_read += inner_read;
798798
available_len -= inner_read;
799799

800-
if (indefinite &&
801-
ossl_asn1_tag(value) == V_ASN1_EOC &&
802-
ossl_asn1_get_tag_class(value) == sym_UNIVERSAL) {
803-
break;
800+
if (indefinite) {
801+
if (ossl_asn1_tag(value) == V_ASN1_EOC &&
802+
ossl_asn1_get_tag_class(value) == sym_UNIVERSAL)
803+
break;
804+
if (available_len == 0)
805+
ossl_raise(eASN1Error, "EOC missing in indefinite length encoding");
804806
}
805807
rb_ary_push(ary, value);
806808
}

test/openssl/test_asn1.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,11 @@ def test_sequence
389389
])
390390
expected.indefinite_length = true
391391
encode_test B(%w{ 30 80 04 01 00 00 00 }), expected
392+
393+
# Missing EOC at the end of contents octets
394+
assert_raise(OpenSSL::ASN1::ASN1Error) {
395+
OpenSSL::ASN1.decode(B(%w{ 30 80 01 01 FF }))
396+
}
392397
end
393398

394399
def test_set

0 commit comments

Comments
 (0)