@@ -509,9 +509,9 @@ Executor::Executor(LLVMContext &ctx, const InterpreterOptions &opts,
509
509
annotationsData(opts.AnnotationsFile, opts.TaintAnnotationsFile),
510
510
interpreterHandler(ih), searcher(nullptr ),
511
511
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()),
515
515
distanceCalculator(new DistanceCalculator(*codeGraphInfo)),
516
516
targetCalculator(new TargetCalculator(*codeGraphInfo)),
517
517
targetManager(new TargetManager(guidanceKind, *distanceCalculator,
@@ -5028,17 +5028,21 @@ void Executor::terminateStateOnTargetError(ExecutionState &state,
5028
5028
}
5029
5029
5030
5030
void 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
+ }
5034
5038
}
5035
5039
5036
- const std::string &ruleStr = annotationsData.taintAnnotation .rules [rule];
5037
5040
reportStateOnTargetError (
5038
- state, ReachWithError (ReachWithErrorType::MaybeTaint, ruleStr ));
5041
+ state, ReachWithError (ReachWithErrorType::MaybeTaint, error ));
5039
5042
5040
- terminateStateOnProgramError (state, ruleStr + " taint error" ,
5041
- StateTerminationType::Taint);
5043
+ terminateStateOnProgramError (
5044
+ state, new ErrorEvent (locationOf (state), StateTerminationType::Taint,
5045
+ error));
5042
5046
}
5043
5047
5044
5048
void Executor::terminateStateOnError (ExecutionState &state,
@@ -5569,9 +5573,10 @@ void Executor::executeChangeTaintSource(ExecutionState &state,
5569
5573
5570
5574
ObjectState *wos = it->second ->addressSpace .getWriteable (mo, os.get ());
5571
5575
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" ));
5575
5580
} else {
5576
5581
wos->updateTaint (Expr::createTaintBySource (source), isAdd);
5577
5582
}
@@ -5613,11 +5618,11 @@ void Executor::executeCheckTaintSource(ExecutionState &state,
5613
5618
}
5614
5619
}
5615
5620
5616
- void Executor::executeGetTaintRule (ExecutionState &state,
5621
+ void Executor::executeGetTaintHits (ExecutionState &state,
5617
5622
klee::KInstruction *target,
5618
5623
ref<PointerExpr> address, uint64_t sink) {
5619
5624
const auto &hitsBySink = annotationsData.taintAnnotation .hits [sink];
5620
- ref<Expr > hitsBySinkTaint = Expr::createEmptyTaint ();
5625
+ ref<ConstantExpr > hitsBySinkTaint = Expr::createEmptyTaint ();
5621
5626
for (const auto [source, rule] : hitsBySink) {
5622
5627
hitsBySinkTaint =
5623
5628
OrExpr::create (hitsBySinkTaint, Expr::createTaintBySource (source));
@@ -5637,7 +5642,7 @@ void Executor::executeGetTaintRule(ExecutionState &state,
5637
5642
if (zeroPointer.second ) {
5638
5643
ExactResolutionList rl;
5639
5644
resolveExact (*zeroPointer.second , address,
5640
- typeSystemManager->getUnknownType (), rl, " getTaintRule " );
5645
+ typeSystemManager->getUnknownType (), rl, " getTaintHits " );
5641
5646
5642
5647
for (Executor::ExactResolutionList::iterator it = rl.begin (), ie = rl.end ();
5643
5648
it != ie; ++it) {
@@ -5647,35 +5652,20 @@ void Executor::executeGetTaintRule(ExecutionState &state,
5647
5652
ref<const ObjectState> os = op.second ;
5648
5653
5649
5654
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);
5667
5656
}
5668
5657
}
5669
5658
}
5670
5659
5671
5660
bool Executor::resolveExact (ExecutionState &estate, ref<Expr> address,
5672
5661
KType *type, ExactResolutionList &results,
5673
5662
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 ());
5676
5665
address = pointer->getValue ();
5677
5666
ref<Expr> base = pointer->getBase ();
5678
- ref<PointerExpr> basePointer = PointerExpr::create (base, base);
5667
+ ref<PointerExpr> basePointer =
5668
+ PointerExpr::create (base, base, address->getTaint ());
5679
5669
ref<Expr> zeroPointer = PointerExpr::create (Expr::createPointer (0 ));
5680
5670
5681
5671
if (SimplifySymIndices) {
0 commit comments