ControlFlowNode
/*** @name Consistency check* @description General consistency check to be run on any and all code. Should never produce any results.* @id py/consistency-check*/import pythonprivate import LegacyPointsToimport analysis.DefinitionTrackingpredicate uniqueness_error(int number, string what, string problem) {what in ["toString", "getLocation", "getNode", "getDefinition", "getEntryNode", "getOrigin","getAnInferredType"] and(number = 0 and problem = "no results for " + what + "()"ornumber in [2 .. 10] and problem = number.toString() + " results for " + what + "()")}predicate ast_consistency(string clsname, string problem, string what) {exists(AstNode a | clsname = a.getAQlClass() |uniqueness_error(count(a.toString()), "toString", problem) andwhat = "at " + a.getLocation().toString()oruniqueness_error(strictcount(a.getLocation()), "getLocation", problem) andwhat = a.getLocation().toString()ornot exists(a.getLocation()) andnot a.(Module).isPackage() andproblem = "no location" andwhat = a.toString())}predicate location_consistency(string clsname, string problem, string what) {exists(Location l | clsname = l.getAQlClass() |uniqueness_error(count(l.toString()), "toString", problem) and what = "at " + l.toString()ornot exists(l.toString()) andproblem = "no toString" and(exists(AstNode thing | thing.getLocation() = l |what = "a location of a " + thing.getAQlClass())ornot exists(AstNode thing | thing.getLocation() = l) andwhat = "a location")orl.getEndLine() < l.getStartLine() andproblem = "end line before start line" andwhat = "at " + l.toString()orl.getEndLine() = l.getStartLine() andl.getEndColumn() < l.getStartColumn() andproblem = "end column before start column" andwhat = "at " + l.toString())}predicate cfg_consistency(string clsname, string problem, string what) {exists(ControlFlowNode f | clsname = f.getAQlClass() |uniqueness_error(count(f.getNode()), "getNode", problem) andwhat = "at " + f.getLocation().toString()ornot exists(f.getLocation()) andnot exists(Module p | p.isPackage() | p.getEntryNode() = f or p.getAnExitNode() = f) andproblem = "no location" andwhat = f.toString()oruniqueness_error(count(f.(AttrNode).getObject()), "getValue", problem) andwhat = "at " + f.getLocation().toString())}predicate scope_consistency(string clsname, string problem, string what) {exists(Scope s | clsname = s.getAQlClass() |uniqueness_error(count(s.getEntryNode()), "getEntryNode", problem) andwhat = "at " + s.getLocation().toString()oruniqueness_error(count(s.toString()), "toString", problem) andwhat = "at " + s.getLocation().toString()oruniqueness_error(strictcount(s.getLocation()), "getLocation", problem) andwhat = "at " + s.getLocation().toString()ornot exists(s.getLocation()) andproblem = "no location" andwhat = s.toString() andnot s.(Module).isPackage())}string best_description_builtin_object(Object o) {o.isBuiltin() and(result = o.toString()ornot exists(o.toString()) and py_cobjectnames(o, result)ornot exists(o.toString()) andnot py_cobjectnames(o, _) andresult = "builtin object of type " + o.getAnInferredType().toString()ornot exists(o.toString()) andnot py_cobjectnames(o, _) andnot exists(o.getAnInferredType().toString()) andresult = "builtin object")}private predicate introspected_builtin_object(Object o) {/** Only check objects from the extractor, missing data for objects generated from C source code analysis is OK.* as it will be ignored if it doesn't match up with the introspected form.*/py_cobject_sources(o, 0)}predicate builtin_object_consistency(string clsname, string problem, string what) {exists(Object o |clsname = o.getAQlClass() andwhat = best_description_builtin_object(o) andintrospected_builtin_object(o)|not exists(o.getAnInferredType()) andnot py_cobjectnames(o, _) andproblem = "neither name nor type"oruniqueness_error(count(string name | py_cobjectnames(o, name)), "name", problem)ornot exists(o.getAnInferredType()) and problem = "no results for getAnInferredType"ornot exists(o.toString()) andproblem = "no toString" andnot exists(string name | name.matches("\\_semmle%") | py_special_objects(o, name)) andnot o = unknownValue())}predicate source_object_consistency(string clsname, string problem, string what) {exists(Object o | clsname = o.getAQlClass() and not o.isBuiltin() |uniqueness_error(count(o.getOrigin()), "getOrigin", problem) andwhat = "at " + o.getOrigin().getLocation().toString()ornot exists(o.getOrigin().getLocation()) and problem = "no location" and what = "??"ornot exists(o.toString()) andproblem = "no toString" andwhat = "at " + o.getOrigin().getLocation().toString()orstrictcount(o.toString()) > 1 and problem = "multiple toStrings()" and what = o.toString())}predicate ssa_consistency(string clsname, string problem, string what) {/* Zero or one definitions of each SSA variable */exists(SsaVariable var | clsname = var.getAQlClass() |uniqueness_error(strictcount(var.getDefinition()), "getDefinition", problem) andwhat = var.getId())or/* Dominance criterion: Definition *must* dominate *all* uses. */exists(SsaVariable var, ControlFlowNode defn, ControlFlowNode use |defn = var.getDefinition() and use = var.getAUse()|not defn.strictlyDominates(use) andnot defn = use and/* Phi nodes which share a flow node with a use come *before* the use */not (exists(var.getAPhiInput()) and defn = use) andclsname = var.getAQlClass() andproblem = "a definition which does not dominate a use at " + use.getLocation() andwhat = var.getId() + " at " + var.getLocation())or/* Minimality of phi nodes */exists(SsaVariable var |strictcount(var.getAPhiInput()) = 1 andvar.getAPhiInput().getDefinition().getBasicBlock().strictlyDominates(var.getDefinition().getBasicBlock())|clsname = var.getAQlClass() andproblem = " a definition which is dominated by the definition of an incoming phi edge." andwhat = var.getId() + " at " + var.getLocation())}predicate function_object_consistency(string clsname, string problem, string what) {exists(FunctionObject func | clsname = func.getAQlClass() |what = func.getName() and(not exists(func.descriptiveString()) and problem = "no descriptiveString()"orexists(int c | c = strictcount(func.descriptiveString()) and c > 1 |problem = c + "descriptiveString()s"))ornot exists(func.getName()) and what = "?" and problem = "no name")}predicate multiple_origins_per_object(Object obj) {not obj.isC() andnot obj instanceof ModuleObject andexists(ControlFlowNodeWithPointsTo use, Context ctx |strictcount(ControlFlowNode orig | use.refersTo(ctx, obj, _, orig)) > 1)}predicate intermediate_origins(ControlFlowNodeWithPointsTo use, ControlFlowNodeWithPointsTo inter, Object obj) {exists(ControlFlowNode orig, Context ctx | not inter = orig |use.refersTo(ctx, obj, _, inter) andinter.refersTo(ctx, obj, _, orig) and// It can sometimes happen that two different modules (e.g. cPickle and Pickle)// have the same attribute, but different origins.not strictcount(Object val |inter.(AttrNode).getObject().(ControlFlowNodeWithPointsTo).refersTo(val)) > 1)}predicate points_to_consistency(string clsname, string problem, string what) {exists(Object obj |multiple_origins_per_object(obj) andclsname = obj.getAQlClass() andproblem = "multiple origins for an object" andwhat = obj.toString())orexists(ControlFlowNode use, ControlFlowNode inter |intermediate_origins(use, inter, _) andclsname = use.getAQlClass() andproblem = "has intermediate origin " + inter andwhat = use.toString())}predicate jump_to_definition_consistency(string clsname, string problem, string what) {problem = "multiple (jump-to) definitions" andexists(Expr use |strictcount(getUniqueDefinition(use)) > 1 andclsname = use.getAQlClass() andwhat = use.toString())}predicate file_consistency(string clsname, string problem, string what) {exists(File file, Folder folder |clsname = file.getAQlClass() andproblem = "has same name as a folder" andwhat = file.getAbsolutePath() andwhat = folder.getAbsolutePath())orexists(Container f |clsname = f.getAQlClass() anduniqueness_error(count(f.toString()), "toString", problem) andwhat = "file " + f.getAbsolutePath())}predicate class_value_consistency(string clsname, string problem, string what) {exists(ClassValue value, ClassValue sup, string attr |what = value.getName() andsup = value.getASuperType() andexists(sup.lookup(attr)) andnot value.failedInference(_) andnot exists(value.lookup(attr)) andclsname = value.getAQlClass() andproblem = "no attribute '" + attr + "', but super type '" + sup.getName() + "' does.")}from string clsname, string problem, string whatwhereast_consistency(clsname, problem, what) orlocation_consistency(clsname, problem, what) orscope_consistency(clsname, problem, what) orcfg_consistency(clsname, problem, what) orssa_consistency(clsname, problem, what) orbuiltin_object_consistency(clsname, problem, what) orsource_object_consistency(clsname, problem, what) orfunction_object_consistency(clsname, problem, what) orpoints_to_consistency(clsname, problem, what) orjump_to_definition_consistency(clsname, problem, what) orfile_consistency(clsname, problem, what) orclass_value_consistency(clsname, problem, what)select clsname + " " + what + " has " + problem
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。