/** * Adds a new result of the data flow analysis to the collection * @param resultAbs The abstraction at the sink instruction */ private void addResult(AbstractionAtSink resultAbs) { // Check whether we need to filter a result in a system package if (ignoreFlowsInSystemPackages && SystemClassHandler.isClassInSystemPackage (interproceduralCFG().getMethodOf(resultAbs.getSinkStmt()).getDeclaringClass().getName())) return; // Make sure that the sink statement also appears inside the // abstraction resultAbs = new AbstractionAtSink (resultAbs.getAbstraction().deriveNewAbstraction (resultAbs.getAbstraction().getAccessPath(), resultAbs.getSinkStmt()), resultAbs.getSinkStmt()); resultAbs.getAbstraction().setCorrespondingCallSite(resultAbs.getSinkStmt()); Abstraction newAbs = this.results.putIfAbsentElseGet (resultAbs, resultAbs.getAbstraction()); if (newAbs != resultAbs.getAbstraction()) newAbs.addNeighbor(resultAbs.getAbstraction()); }
/** * Scans the given method for sources and sinks contained in it. Sinks are * just counted, sources are added to the InfoflowProblem as seeds. * @param sourcesSinks The SourceSinkManager to be used for identifying * sources and sinks * @param forwardProblem The InfoflowProblem in which to register the * sources as seeds * @param m The method to scan for sources and sinks * @return The number of sinks found in this method */ private int scanMethodForSourcesSinks( final ISourceSinkManager sourcesSinks, InfoflowProblem forwardProblem, SootMethod m) { int sinkCount = 0; if (m.hasActiveBody()) { // Check whether this is a system class we need to ignore final String className = m.getDeclaringClass().getName(); if (ignoreFlowsInSystemPackages && SystemClassHandler.isClassInSystemPackage(className)) return sinkCount; // Look for a source in the method. Also look for sinks. If we // have no sink in the program, we don't need to perform any // analysis PatchingChain<Unit> units = m.getActiveBody().getUnits(); for (Unit u : units) { Stmt s = (Stmt) u; if (sourcesSinks.getSourceInfo(s, iCfg) != null) { forwardProblem.addInitialSeeds(u, Collections.singleton(forwardProblem.zeroValue())); logger.debug("Source found: {}", u); } if (sourcesSinks.isSink(s, iCfg, null)) { logger.debug("Sink found: {}", u); sinkCount++; } } } return sinkCount; }