@@ -509,9 +509,9 @@ Executor::Executor(LLVMContext &ctx, const InterpreterOptions &opts,
509509 annotationsData(opts.AnnotationsFile, opts.TaintAnnotationsFile),
510510 interpreterHandler(ih), searcher(nullptr ),
511511 externalDispatcher(new ExternalDispatcher(ctx)), statsTracker(0 ),
512- pathWriter(0 ), symPathWriter(0 ),
513- specialFunctionHandler( 0 ), timers{time::Span (TimerInterval)},
514- guidanceKind (opts.Guidance), codeGraphInfo(new CodeGraphInfo()),
512+ pathWriter(0 ), symPathWriter(0 ), specialFunctionHandler( 0 ),
513+ timers{time::Span (TimerInterval)}, guidanceKind(opts.Guidance) ,
514+ codeGraphInfo(new CodeGraphInfo()),
515515 distanceCalculator(new DistanceCalculator(*codeGraphInfo)),
516516 targetCalculator(new TargetCalculator(*codeGraphInfo)),
517517 targetManager(new TargetManager(guidanceKind, *distanceCalculator,
@@ -5028,17 +5028,21 @@ void Executor::terminateStateOnTargetError(ExecutionState &state,
50285028}
50295029
50305030void Executor::terminateStateOnTargetTaintError (ExecutionState &state,
5031- uint64_t rule) {
5032- if (rule >= annotationsData.taintAnnotation .rules .size ()) {
5033- terminateStateOnUserError (state, " Incorrect rule id" );
5031+ uint64_t hits, size_t sink) {
5032+ std::string error = " Taint error:" ;
5033+ const auto &sinkData = annotationsData.taintAnnotation .hits .at (sink);
5034+ for (size_t source = 0 ; source < annotationsData.taintAnnotation .sources .size (); source++) {
5035+ if ((hits >> source) & 1u ) {
5036+ error += " " + annotationsData.taintAnnotation .rules [sinkData.at (source)];
5037+ }
50345038 }
50355039
5036- const std::string &ruleStr = annotationsData.taintAnnotation .rules [rule];
50375040 reportStateOnTargetError (
5038- state, ReachWithError (ReachWithErrorType::MaybeTaint, ruleStr ));
5041+ state, ReachWithError (ReachWithErrorType::MaybeTaint, error ));
50395042
5040- terminateStateOnProgramError (state, ruleStr + " taint error" ,
5041- StateTerminationType::Taint);
5043+ terminateStateOnProgramError (
5044+ state, new ErrorEvent (locationOf (state), StateTerminationType::Taint,
5045+ error));
50425046}
50435047
50445048void Executor::terminateStateOnError (ExecutionState &state,
@@ -5569,9 +5573,10 @@ void Executor::executeChangeTaintSource(ExecutionState &state,
55695573
55705574 ObjectState *wos = it->second ->addressSpace .getWriteable (mo, os.get ());
55715575 if (wos->readOnly ) {
5572- terminateStateOnProgramError (*(it->second ),
5573- " memory error: object read only" ,
5574- StateTerminationType::ReadOnly);
5576+ terminateStateOnProgramError (
5577+ *(it->second ), new ErrorEvent (locationOf (*(it->second )),
5578+ StateTerminationType::ReadOnly,
5579+ " memory error: object read only" ));
55755580 } else {
55765581 wos->updateTaint (Expr::createTaintBySource (source), isAdd);
55775582 }
@@ -5613,11 +5618,11 @@ void Executor::executeCheckTaintSource(ExecutionState &state,
56135618 }
56145619}
56155620
5616- void Executor::executeGetTaintRule (ExecutionState &state,
5621+ void Executor::executeGetTaintHits (ExecutionState &state,
56175622 klee::KInstruction *target,
56185623 ref<PointerExpr> address, uint64_t sink) {
56195624 const auto &hitsBySink = annotationsData.taintAnnotation .hits [sink];
5620- ref<Expr > hitsBySinkTaint = Expr::createEmptyTaint ();
5625+ ref<ConstantExpr > hitsBySinkTaint = Expr::createEmptyTaint ();
56215626 for (const auto [source, rule] : hitsBySink) {
56225627 hitsBySinkTaint =
56235628 OrExpr::create (hitsBySinkTaint, Expr::createTaintBySource (source));
@@ -5637,7 +5642,7 @@ void Executor::executeGetTaintRule(ExecutionState &state,
56375642 if (zeroPointer.second ) {
56385643 ExactResolutionList rl;
56395644 resolveExact (*zeroPointer.second , address,
5640- typeSystemManager->getUnknownType (), rl, " getTaintRule " );
5645+ typeSystemManager->getUnknownType (), rl, " getTaintHits " );
56415646
56425647 for (Executor::ExactResolutionList::iterator it = rl.begin (), ie = rl.end ();
56435648 it != ie; ++it) {
@@ -5647,35 +5652,20 @@ void Executor::executeGetTaintRule(ExecutionState &state,
56475652 ref<const ObjectState> os = op.second ;
56485653
56495654 ref<Expr> hits = AndExpr::create (os->readTaint (), hitsBySinkTaint);
5650-
5651- auto curState = it->second ;
5652- for (size_t source = 0 ;
5653- source < annotationsData.taintAnnotation .sources .size (); source++) {
5654- ref<Expr> taintSource = ExtractExpr::create (hits, source, Expr::Bool);
5655- StatePair taintSourceStates =
5656- forkInternal (*curState, taintSource, BranchType::Taint);
5657- if (taintSourceStates.first ) {
5658- bindLocal (target, *taintSourceStates.first ,
5659- ConstantExpr::create (hitsBySink.at (source) + 1 ,
5660- Expr::Int64)); // return (rule + 1)
5661- }
5662- if (taintSourceStates.second ) {
5663- curState = taintSourceStates.second ;
5664- }
5665- }
5666- bindLocal (target, *curState, ConstantExpr::create (0 , Expr::Int64));
5655+ bindLocal (target, *it->second , hits);
56675656 }
56685657 }
56695658}
56705659
56715660bool Executor::resolveExact (ExecutionState &estate, ref<Expr> address,
56725661 KType *type, ExactResolutionList &results,
56735662 const std::string &name) {
5674- ref<PointerExpr> pointer =
5675- PointerExpr::create ( address->getValue (), address->getValue ());
5663+ ref<PointerExpr> pointer = PointerExpr::create (
5664+ address->getValue (), address->getValue (), address-> getTaint ());
56765665 address = pointer->getValue ();
56775666 ref<Expr> base = pointer->getBase ();
5678- ref<PointerExpr> basePointer = PointerExpr::create (base, base);
5667+ ref<PointerExpr> basePointer =
5668+ PointerExpr::create (base, base, address->getTaint ());
56795669 ref<Expr> zeroPointer = PointerExpr::create (Expr::createPointer (0 ));
56805670
56815671 if (SimplifySymIndices) {
0 commit comments