aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2017-04-13 14:46:52 -0400
committerJack Lloyd <[email protected]>2017-04-13 14:46:52 -0400
commit92a888921a877e73951b6c256429bfae0356b22f (patch)
treedf5024aaef4d5f3288d4d18ac7a1a720f040c8dc /src/lib
parent4737338d1810c3a8934d83a2579c3772afe53768 (diff)
parentcd72f4ac0bfc6ff5ecafb804e6c61c8d2902d6c4 (diff)
Merge GH #989 Avoid recursion in BER_Decoder::get_next_object
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/asn1/ber_dec.cpp27
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;
}