@@ -5028,7 +5028,7 @@ void Executor::terminateStateOnTargetError(ExecutionState &state,
50285028}
50295029
50305030void Executor::terminateStateOnTargetTaintError (ExecutionState &state,
5031- size_t rule) {
5031+ uint64_t rule) {
50325032 if (rule >= annotationsData.taintAnnotation .rules .size ()) {
50335033 terminateStateOnUserError (state, " Incorrect rule id" );
50345034 }
@@ -5541,6 +5541,133 @@ void Executor::executeFree(ExecutionState &state, ref<PointerExpr> address,
55415541 }
55425542}
55435543
5544+ void Executor::executeChangeTaintSource (ExecutionState &state,
5545+ klee::KInstruction *target,
5546+ ref<PointerExpr> address,
5547+ uint64_t source, bool isAdd) {
5548+ address = optimizer.optimizeExpr (address, true );
5549+ ref<Expr> isNullPointer = Expr::createIsZero (address->getValue ());
5550+ StatePair zeroPointer =
5551+ forkInternal (state, isNullPointer, BranchType::ResolvePointer);
5552+ if (zeroPointer.first ) {
5553+ auto error =
5554+ (isReadFromSymbolicArray (address->getBase ()) && zeroPointer.second )
5555+ ? ReachWithErrorType::MayBeNullPointerException
5556+ : ReachWithErrorType::MustBeNullPointerException;
5557+ terminateStateOnTargetError (*zeroPointer.first , ReachWithError (error));
5558+ }
5559+ if (zeroPointer.second ) { // address != 0
5560+ ExactResolutionList rl;
5561+ resolveExact (*zeroPointer.second , address,
5562+ typeSystemManager->getUnknownType (), rl, " сhangeTaintSource" );
5563+ for (Executor::ExactResolutionList::iterator it = rl.begin (), ie = rl.end ();
5564+ it != ie; ++it) {
5565+ const MemoryObject *mo = it->first ;
5566+ RefObjectPair op =
5567+ it->second ->addressSpace .findOrLazyInitializeObject (mo);
5568+ ref<const ObjectState> os = op.second ;
5569+
5570+ ObjectState *wos = it->second ->addressSpace .getWriteable (mo, os.get ());
5571+ if (wos->readOnly ) {
5572+ terminateStateOnProgramError (*(it->second ),
5573+ " memory error: object read only" ,
5574+ StateTerminationType::ReadOnly);
5575+ } else {
5576+ wos->updateTaint (Expr::createTaintBySource (source), isAdd);
5577+ }
5578+ }
5579+ }
5580+ }
5581+
5582+ void Executor::executeCheckTaintSource (ExecutionState &state,
5583+ klee::KInstruction *target,
5584+ ref<PointerExpr> address,
5585+ uint64_t source) {
5586+ address = optimizer.optimizeExpr (address, true );
5587+ ref<Expr> isNullPointer = Expr::createIsZero (address->getValue ());
5588+ StatePair zeroPointer =
5589+ forkInternal (state, isNullPointer, BranchType::ResolvePointer);
5590+ if (zeroPointer.first ) {
5591+ auto error =
5592+ (isReadFromSymbolicArray (address->getBase ()) && zeroPointer.second )
5593+ ? ReachWithErrorType::MayBeNullPointerException
5594+ : ReachWithErrorType::MustBeNullPointerException;
5595+ terminateStateOnTargetError (*zeroPointer.first , ReachWithError (error));
5596+ }
5597+ if (zeroPointer.second ) {
5598+ ExactResolutionList rl;
5599+ resolveExact (*zeroPointer.second , address,
5600+ typeSystemManager->getUnknownType (), rl, " checkTaintSource" );
5601+
5602+ for (Executor::ExactResolutionList::iterator it = rl.begin (), ie = rl.end ();
5603+ it != ie; ++it) {
5604+ const MemoryObject *mo = it->first ;
5605+ RefObjectPair op =
5606+ it->second ->addressSpace .findOrLazyInitializeObject (mo);
5607+ ref<const ObjectState> os = op.second ;
5608+
5609+ ref<Expr> taintSource =
5610+ ExtractExpr::create (os->readTaint (), source, Expr::Bool);
5611+ bindLocal (target, *it->second , taintSource);
5612+ }
5613+ }
5614+ }
5615+
5616+ void Executor::executeGetTaintRule (ExecutionState &state,
5617+ klee::KInstruction *target,
5618+ ref<PointerExpr> address, uint64_t sink) {
5619+ const auto &hitsBySink = annotationsData.taintAnnotation .hits [sink];
5620+ ref<Expr> hitsBySinkTaint = Expr::createEmptyTaint ();
5621+ for (const auto [source, rule] : hitsBySink) {
5622+ hitsBySinkTaint =
5623+ OrExpr::create (hitsBySinkTaint, Expr::createTaintBySource (source));
5624+ }
5625+
5626+ address = optimizer.optimizeExpr (address, true );
5627+ ref<Expr> isNullPointer = Expr::createIsZero (address->getValue ());
5628+ StatePair zeroPointer =
5629+ forkInternal (state, isNullPointer, BranchType::ResolvePointer);
5630+ if (zeroPointer.first ) {
5631+ auto error =
5632+ (isReadFromSymbolicArray (address->getBase ()) && zeroPointer.second )
5633+ ? ReachWithErrorType::MayBeNullPointerException
5634+ : ReachWithErrorType::MustBeNullPointerException;
5635+ terminateStateOnTargetError (*zeroPointer.first , ReachWithError (error));
5636+ }
5637+ if (zeroPointer.second ) {
5638+ ExactResolutionList rl;
5639+ resolveExact (*zeroPointer.second , address,
5640+ typeSystemManager->getUnknownType (), rl, " getTaintRule" );
5641+
5642+ for (Executor::ExactResolutionList::iterator it = rl.begin (), ie = rl.end ();
5643+ it != ie; ++it) {
5644+ const MemoryObject *mo = it->first ;
5645+ RefObjectPair op =
5646+ it->second ->addressSpace .findOrLazyInitializeObject (mo);
5647+ ref<const ObjectState> os = op.second ;
5648+
5649+ 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));
5667+ }
5668+ }
5669+ }
5670+
55445671bool Executor::resolveExact (ExecutionState &estate, ref<Expr> address,
55455672 KType *type, ExactResolutionList &results,
55465673 const std::string &name) {
0 commit comments