ExprEngine: Catch and handle exceptions in ExprData

This commit is contained in:
Daniel Marjamäki 2020-12-12 17:33:10 +01:00
parent 4b079c8934
commit cba8b99095
1 changed files with 53 additions and 8 deletions

View File

@ -1213,6 +1213,10 @@ bool ExprEngine::IntRange::isEqual(DataBase *dataBase, int value) const
} catch (const z3::exception &exception) { } catch (const z3::exception &exception) {
std::cerr << "z3: " << exception << std::endl; std::cerr << "z3: " << exception << std::endl;
return true; // Safe option is to return true return true; // Safe option is to return true
} catch (const ExprData::BailoutValueException &) {
return true; // Safe option is to return true
} catch (const ExprEngineException &) {
return true; // Safe option is to return true
} }
#else #else
// The value may or may not be in range // The value may or may not be in range
@ -1241,6 +1245,10 @@ bool ExprEngine::IntRange::isGreaterThan(DataBase *dataBase, int value) const
} catch (const z3::exception &exception) { } catch (const z3::exception &exception) {
std::cerr << "z3: " << exception << std::endl; std::cerr << "z3: " << exception << std::endl;
return true; // Safe option is to return true return true; // Safe option is to return true
} catch (const ExprData::BailoutValueException &) {
return true; // Safe option is to return true
} catch (const ExprEngineException &) {
return true; // Safe option is to return true
} }
#else #else
// The value may or may not be in range // The value may or may not be in range
@ -1269,6 +1277,10 @@ bool ExprEngine::IntRange::isLessThan(DataBase *dataBase, int value) const
} catch (const z3::exception &exception) { } catch (const z3::exception &exception) {
std::cerr << "z3: " << exception << std::endl; std::cerr << "z3: " << exception << std::endl;
return true; // Safe option is to return true return true; // Safe option is to return true
} catch (const ExprData::BailoutValueException &) {
return true; // Safe option is to return true
} catch (const ExprEngineException &) {
return true; // Safe option is to return true
} }
#else #else
// The value may or may not be in range // The value may or may not be in range
@ -1298,6 +1310,10 @@ bool ExprEngine::FloatRange::isEqual(DataBase *dataBase, int value) const
} catch (const z3::exception &exception) { } catch (const z3::exception &exception) {
std::cerr << "z3: " << exception << std::endl; std::cerr << "z3: " << exception << std::endl;
return true; // Safe option is to return true return true; // Safe option is to return true
} catch (const ExprData::BailoutValueException &) {
return true; // Safe option is to return true
} catch (const ExprEngineException &) {
return true; // Safe option is to return true
} }
#else #else
// The value may or may not be in range // The value may or may not be in range
@ -1328,6 +1344,10 @@ bool ExprEngine::FloatRange::isGreaterThan(DataBase *dataBase, int value) const
} catch (const z3::exception &exception) { } catch (const z3::exception &exception) {
std::cerr << "z3: " << exception << std::endl; std::cerr << "z3: " << exception << std::endl;
return true; // Safe option is to return true return true; // Safe option is to return true
} catch (const ExprData::BailoutValueException &) {
return true; // Safe option is to return true
} catch (const ExprEngineException &) {
return true; // Safe option is to return true
} }
#else #else
// The value may or may not be in range // The value may or may not be in range
@ -1358,6 +1378,10 @@ bool ExprEngine::FloatRange::isLessThan(DataBase *dataBase, int value) const
} catch (const z3::exception &exception) { } catch (const z3::exception &exception) {
std::cerr << "z3: " << exception << std::endl; std::cerr << "z3: " << exception << std::endl;
return true; // Safe option is to return true return true; // Safe option is to return true
} catch (const ExprData::BailoutValueException &) {
return true; // Safe option is to return true
} catch (const ExprEngineException &) {
return true; // Safe option is to return true
} }
#else #else
// The value may or may not be in range // The value may or may not be in range
@ -1369,6 +1393,7 @@ bool ExprEngine::FloatRange::isLessThan(DataBase *dataBase, int value) const
bool ExprEngine::BinOpResult::isEqual(ExprEngine::DataBase *dataBase, int value) const bool ExprEngine::BinOpResult::isEqual(ExprEngine::DataBase *dataBase, int value) const
{ {
#ifdef USE_Z3 #ifdef USE_Z3
try {
ExprData exprData; ExprData exprData;
z3::solver solver(exprData.context); z3::solver solver(exprData.context);
z3::expr e = exprData.getExpr(this); z3::expr e = exprData.getExpr(this);
@ -1376,6 +1401,14 @@ bool ExprEngine::BinOpResult::isEqual(ExprEngine::DataBase *dataBase, int value)
exprData.addAssertions(solver); exprData.addAssertions(solver);
solver.add(exprData.int_expr(e) == value); solver.add(exprData.int_expr(e) == value);
return solver.check() == z3::sat; return solver.check() == z3::sat;
} catch (const z3::exception &exception) {
std::cerr << "z3:" << exception << std::endl;
return true; // Safe option is to return true
} catch (const ExprData::BailoutValueException &) {
return true; // Safe option is to return true
} catch (const ExprEngineException &) {
return true; // Safe option is to return true
}
#else #else
(void)dataBase; (void)dataBase;
(void)value; (void)value;
@ -1397,6 +1430,10 @@ bool ExprEngine::BinOpResult::isGreaterThan(ExprEngine::DataBase *dataBase, int
} catch (const z3::exception &exception) { } catch (const z3::exception &exception) {
std::cerr << "z3:" << exception << std::endl; std::cerr << "z3:" << exception << std::endl;
return true; // Safe option is to return true return true; // Safe option is to return true
} catch (const ExprData::BailoutValueException &) {
return true; // Safe option is to return true
} catch (const ExprEngineException &) {
return true; // Safe option is to return true
} }
#else #else
(void)dataBase; (void)dataBase;
@ -1419,6 +1456,10 @@ bool ExprEngine::BinOpResult::isLessThan(ExprEngine::DataBase *dataBase, int val
} catch (const z3::exception &exception) { } catch (const z3::exception &exception) {
std::cerr << "z3:" << exception << std::endl; std::cerr << "z3:" << exception << std::endl;
return true; // Safe option is to return true return true; // Safe option is to return true
} catch (const ExprData::BailoutValueException &) {
return true; // Safe option is to return true
} catch (const ExprEngineException &) {
return true; // Safe option is to return true
} }
#else #else
(void)dataBase; (void)dataBase;
@ -1441,6 +1482,10 @@ bool ExprEngine::BinOpResult::isTrue(ExprEngine::DataBase *dataBase) const
} catch (const z3::exception &exception) { } catch (const z3::exception &exception) {
std::cerr << "z3:" << exception << std::endl; std::cerr << "z3:" << exception << std::endl;
return true; // Safe option is to return true return true; // Safe option is to return true
} catch (const ExprData::BailoutValueException &) {
return true; // Safe option is to return true
} catch (const ExprEngineException &) {
return true; // Safe option is to return true
} }
#else #else
(void)dataBase; (void)dataBase;
@ -2688,7 +2733,7 @@ void ExprEngine::executeFunction(const Scope *functionScope, ErrorLogger *errorL
try { try {
execute(functionScope->bodyStart, functionScope->bodyEnd, data); execute(functionScope->bodyStart, functionScope->bodyEnd, data);
} catch (ExprEngineException &e) { } catch (const ExprEngineException &e) {
if (settings->debugBugHunting) if (settings->debugBugHunting)
report << "ExprEngineException tok.line:" << e.tok->linenr() << " what:" << e.what << "\n"; report << "ExprEngineException tok.line:" << e.tok->linenr() << " what:" << e.what << "\n";
trackExecution.setAbortLine(e.tok->linenr()); trackExecution.setAbortLine(e.tok->linenr());