3333#include " llvm/IR/LLVMContext.h"
3434#include " llvm/IR/Value.h"
3535#include " llvm/Support/Casting.h"
36+ #include " llvm/Support/WithColor.h"
3637#include " llvm/Support/raw_ostream.h"
3738
3839#include < utility>
@@ -280,8 +281,8 @@ auto IFDSTaintAnalysis::getNormalFlowFunction(n_t Curr,
280281 Gen.insert (Store->getValueOperand ());
281282 }
282283
283- return lambdaFlow (
284- [Store, Gen{std::move (Gen)}](d_t Source) -> container_type {
284+ auto Ret =
285+ lambdaFlow ( [Store, Gen{std::move (Gen)}](d_t Source) -> container_type {
285286 if (Store->getPointerOperand () == Source) {
286287 return {};
287288 }
@@ -291,6 +292,21 @@ auto IFDSTaintAnalysis::getNormalFlowFunction(n_t Curr,
291292
292293 return {Source};
293294 });
295+ if (Config->isSink (Store->getPointerOperand ())) {
296+ // Handle sink variables:
297+
298+ return lambdaFlow ([this , Store, Ret = std::move (Ret)](d_t Source) {
299+ if (Store->getValueOperand () == Source) {
300+ if (Leaks[Store].insert (Source).second ) {
301+ Printer->onResult (Store, Source,
302+ DataFlowAnalysisType::IFDSTaintAnalysis);
303+ }
304+ }
305+
306+ return Ret->computeTargets (Source);
307+ });
308+ }
309+ return Ret;
294310 }
295311 // If a tainted value is loaded, the loaded value is of course tainted
296312 if (const auto *Load = llvm::dyn_cast<llvm::LoadInst>(Curr)) {
@@ -316,6 +332,16 @@ auto IFDSTaintAnalysis::getNormalFlowFunction(n_t Curr,
316332 return transferFlow (Cast, Cast->getOperand (0 ));
317333 }
318334
335+ if (llvm::isa<llvm::BinaryOperator>(Curr)) {
336+ return lambdaFlow ([Curr](d_t Source) -> container_type {
337+ if (llvm::is_contained (Curr->operand_values (), Source)) {
338+ return {Source, Curr};
339+ }
340+
341+ return {Source};
342+ });
343+ }
344+
319345 // Otherwise we do not care and leave everything as it is
320346 return identityFlow ();
321347}
@@ -489,7 +515,10 @@ auto IFDSTaintAnalysis::getSummaryFlowFunction([[maybe_unused]] n_t CallSite,
489515auto IFDSTaintAnalysis::initialSeeds () -> InitialSeeds<n_t, d_t, l_t> {
490516 PHASAR_LOG_LEVEL (DEBUG, " IFDSTaintAnalysis::initialSeeds()" );
491517
492- InitialSeeds<n_t , d_t , l_t > Seeds;
518+ // Instructions are generated from zero on-the-fly, but args must be generated
519+ // explicitly as seeds
520+ InitialSeeds<n_t , d_t , l_t > Seeds =
521+ Config->makeInitialSeeds (LLVMTaintConfig::SeedConfig::Arguments);
493522
494523 LLVMBasedCFG C;
495524 addSeedsForStartingPoints (EntryPoints, IRDB, C, Seeds, getZeroValue (),
@@ -507,6 +536,13 @@ auto IFDSTaintAnalysis::initialSeeds() -> InitialSeeds<n_t, d_t, l_t> {
507536 }
508537 }
509538
539+ if (Seeds.empty ()) {
540+ llvm::WithColor::warning ()
541+ << " No initial seeds specified, skip the analysis. "
542+ " Please specify an entrypoint function or in the "
543+ " TaintConfig a source llvm::Instruction*\n " ;
544+ }
545+
510546 return Seeds;
511547}
512548
0 commit comments