import pythonimport Loopimport semmle.python.dataflow.TaintTrackingprivate import LegacyPointsTo/** A marker for "uninitialized". */class Uninitialized extends TaintKind {Uninitialized() { this = "undefined" }}private predicate loop_entry_variables(EssaVariable pred, EssaVariable succ) {exists(PhiFunction phi, BasicBlock pb |loop_entry_edge(pb, phi.getBasicBlock()) andsucc = phi.getVariable() andpred = phi.getInput(pb))}private predicate loop_entry_edge(BasicBlock pred, BasicBlock loop) {pred = loop.getAPredecessor() andpred = loop.getImmediateDominator() andexists(Stmt s |loop_probably_executes_at_least_once(s) ands.getAFlowNode().getBasicBlock() = loop)}/*** Since any use of a local will raise if it is uninitialized, then* any use dominated by another use of the same variable must be defined, or is unreachable.*/private predicate first_use(NameNode u, EssaVariable v) {v.getASourceUse() = u andnot exists(NameNode other |v.getASourceUse() = other andother.strictlyDominates(u))}/*** Holds if `call` is a call of the form obj.method_name(...) and* there is a function called `method_name` that can exit the program.*/private predicate maybe_call_to_exiting_function(CallNode call) {exists(FunctionValue exits, string name | exits.neverReturns() and exits.getName() = name |call.getFunction().(NameNode).getId() = name orcall.getFunction().(AttrNode).getName() = name)}predicate exitFunctionGuardedEdge(EssaVariable pred, EssaVariable succ) {exists(CallNode exit_call |succ.(PhiFunction).getInput(exit_call.getBasicBlock()) = pred andmaybe_call_to_exiting_function(exit_call))}class UninitializedConfig extends TaintTracking::Configuration {UninitializedConfig() { this = "Uninitialized local config" }override predicate isSource(DataFlow::Node source, TaintKind kind) {kind instanceof Uninitialized andexists(EssaVariable var |source.asVariable() = var andvar.getSourceVariable() instanceof FastLocalVariable andnot var.getSourceVariable().(Variable).escapes()|var instanceof ScopeEntryDefinitionorvar instanceof DeletionDefinition)}override predicate isBarrier(DataFlow::Node node, TaintKind kind) {kind instanceof Uninitialized and(this.definition(node.asVariable())orthis.use(node.asVariable())orthis.sanitizingNode(node.asCfgNode()))}private predicate definition(EssaDefinition def) {def instanceof AssignmentDefinitionordef instanceof ExceptionCaptureordef instanceof ParameterDefinition}private predicate use(EssaDefinition def) {exists(def.(EssaNodeRefinement).getInput().getASourceUse())orexists(def.(PhiFunction).getAnInput().getASourceUse())orexists(def.(EssaEdgeRefinement).getInput().getASourceUse())}private predicate sanitizingNode(ControlFlowNode node) {exists(EssaVariable v |v.getASourceUse() = node andnot first_use(node, v))}override predicate isBarrierEdge(DataFlow::Node src, DataFlow::Node dest) {/** If we are guaranteed to iterate over a loop at least once, then we can prune any edges that* don't pass through the body.*/loop_entry_variables(src.asVariable(), dest.asVariable())orexitFunctionGuardedEdge(src.asVariable(), dest.asVariable())}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。