From f14497dba0b32ff8a7f0514ec6dae961458f9aa5 Mon Sep 17 00:00:00 2001 From: Arash Partow Date: Mon, 7 Dec 2020 06:52:24 +1100 Subject: [PATCH] [exprtk] Enable loop upper-bound runtime checks in the fuzzer (#4789) --- projects/exprtk/exprtk_fuzzer.cpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/projects/exprtk/exprtk_fuzzer.cpp b/projects/exprtk/exprtk_fuzzer.cpp index 6612fa1b7..4adfe1d5a 100644 --- a/projects/exprtk/exprtk_fuzzer.cpp +++ b/projects/exprtk/exprtk_fuzzer.cpp @@ -15,15 +15,17 @@ #include #include +#define exprtk_enable_runtime_checks #include "exprtk.hpp" template void run(const std::string& expression_string) { - typedef exprtk::symbol_table symbol_table_t; - typedef exprtk::expression expression_t; - typedef exprtk::parser parser_t; + typedef exprtk::symbol_table symbol_table_t; + typedef exprtk::expression expression_t; + typedef exprtk::parser parser_t; + typedef exprtk::loop_runtime_check loop_runtime_check_t; T x = T(1.2345); T y = T(2.2345); @@ -40,10 +42,24 @@ void run(const std::string& expression_string) expression_t expression; expression.register_symbol_table(symbol_table); + loop_runtime_check_t loop_runtime_check; + loop_runtime_check.loop_set = loop_runtime_check_t::e_all_loops; + loop_runtime_check.max_loop_iterations = 100000000; + parser_t parser; + + parser.register_loop_runtime_check(loop_runtime_check); + if (parser.compile(expression_string, expression)) { - expression.value(); + try + { + expression.value(); + } + catch (std::runtime_error& rte) + {} + + parser.clear_loop_runtime_check(); } }