diff options
author | Jack Lloyd <[email protected]> | 2017-04-09 12:27:02 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2017-04-09 12:27:02 -0400 |
commit | 5c79da3a4fd6ac45047834681c3efd8fba3c7825 (patch) | |
tree | 1e3965660341aa6ef27bb5435501002a0b32127a /src/lib/asn1/ber_dec.cpp | |
parent | d5d2cca6ef78edafe682c5ab372ef6cbf1a70469 (diff) |
Avoid recursion in BER_Decoder::get_next_object
Diffstat (limited to 'src/lib/asn1/ber_dec.cpp')
-rw-r--r-- | src/lib/asn1/ber_dec.cpp | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/src/lib/asn1/ber_dec.cpp b/src/lib/asn1/ber_dec.cpp index 7b2147600..bf728a8e8 100644 --- a/src/lib/asn1/ber_dec.cpp +++ b/src/lib/asn1/ber_dec.cpp @@ -218,20 +218,25 @@ BER_Object BER_Decoder::get_next_object() return next; } - decode_tag(m_source, next.type_tag, next.class_tag); - if(next.type_tag == NO_OBJECT) - return next; + for(;;) + { + decode_tag(m_source, next.type_tag, next.class_tag); + if(next.type_tag == NO_OBJECT) + return next; - const size_t length = decode_length(m_source); - if(!m_source->check_available(length)) - throw BER_Decoding_Error("Value truncated"); + const size_t length = decode_length(m_source); + if(!m_source->check_available(length)) + throw BER_Decoding_Error("Value truncated"); - next.value.resize(length); - if(m_source->read(next.value.data(), length) != length) - throw BER_Decoding_Error("Value truncated"); + next.value.resize(length); + if(m_source->read(next.value.data(), length) != length) + throw BER_Decoding_Error("Value truncated"); - if(next.type_tag == EOC && next.class_tag == UNIVERSAL) - return get_next_object(); + if(next.type_tag == EOC && next.class_tag == UNIVERSAL) + continue; + else + break; + } return next; } |