diff options
author | Jack Lloyd <[email protected]> | 2017-04-13 14:46:52 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2017-04-13 14:46:52 -0400 |
commit | 92a888921a877e73951b6c256429bfae0356b22f (patch) | |
tree | df5024aaef4d5f3288d4d18ac7a1a720f040c8dc /src/tests | |
parent | 4737338d1810c3a8934d83a2579c3772afe53768 (diff) | |
parent | cd72f4ac0bfc6ff5ecafb804e6c61c8d2902d6c4 (diff) |
Merge GH #989 Avoid recursion in BER_Decoder::get_next_object
Diffstat (limited to 'src/tests')
-rw-r--r-- | src/tests/test_asn1.cpp | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/src/tests/test_asn1.cpp b/src/tests/test_asn1.cpp new file mode 100644 index 000000000..3427d391d --- /dev/null +++ b/src/tests/test_asn1.cpp @@ -0,0 +1,67 @@ +/* +* (C) 2017 Jack Lloyd +* +* Botan is released under the Simplified BSD License (see license.txt) +*/ + +#include "tests.h" + +#if defined(BOTAN_HAS_ASN1) + #include <botan/der_enc.h> + #include <botan/ber_dec.h> +#endif + +namespace Botan_Tests { + +#if defined(BOTAN_HAS_ASN1) + +namespace { + +Test::Result test_ber_stack_recursion() + { + Test::Result result("BER stack recursion"); + + // OSS-Fuzz #813 GitHub #989 + + try + { + const std::vector<uint8_t> in(10000000, 0); + Botan::DataSource_Memory input(in.data(), in.size()); + Botan::BER_Decoder dec(input); + + while(dec.more_items()) + { + Botan::BER_Object obj; + dec.get_next(obj); + } + } + catch(Botan::Decoding_Error&) + { + } + + result.test_success("No crash"); + + return result; + } + +} + +class ASN1_Tests : public Test + { + public: + std::vector<Test::Result> run() override + { + std::vector<Test::Result> results; + + results.push_back(test_ber_stack_recursion()); + + return results; + } + }; + +BOTAN_REGISTER_TEST("asn1", ASN1_Tests); + +#endif + +} + |