GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — codeql/java/ql/src/Telemetry/ExternalApi.qll at codeql-cli/v2.24.2 · github/codeql Expand file tree/ Copy pathExternalApi.qllMore file actions 135 lines (117 loc) · 4.44 KB / Copy pathExternalApi.qllFile metadata and controls135 lines (117 loc) · 4.44 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 /** Provides classes and predicates related to handling APIs from external libraries. */ private import java private import semmle.code.java.dataflow.ApiSources as ApiSources private import semmle.code.java.dataflow.ApiSinks as ApiSinks private import semmle.code.java.dataflow.DataFlow private import semmle.code.java.dataflow.ExternalFlow private import semmle.code.java.dataflow.FlowSources private import semmle.code.java.dataflow.FlowSummary private import semmle.code.java.dataflow.internal.DataFlowPrivate private import semmle.code.java.dataflow.internal.FlowSummaryImpl as FlowSummaryImpl private import semmle.code.java.dataflow.TaintTracking private import semmle.code.java.dataflow.internal.ModelExclusions /** Holds if the given callable is not worth supporting. */ private predicate isUninteresting(Callable c) { c.getDeclaringType() instanceof TestLibrary or c.(Constructor).isParameterless() } /** * An external API from either the Standard Library or a 3rd party library. */ class ExternalApi extends Callable { ExternalApi() { not this.fromSource() and not isUninteresting(this) } /** * Gets information about the external API in the form expected by the MaD modeling framework. */ string getApiName() { result = this.getDeclaringType().getPackage() + "." + this.getDeclaringType().getSourceDeclaration().getNestedName() + "#" + this.getName() + paramsString(this) } private string getJarName() { result = this.getCompilationUnit().getParentContainer*().(JarFile).getBaseName() } /** * Gets the jar file containing this API. Normalizes the Java Runtime to "rt.jar" despite the presence of modules. */ string jarContainer() { result = this.getJarName() or not exists(this.getJarName()) and result = "rt.jar" } /** Gets a node that is an input to a call to this API. */ private DataFlow::Node getAnInput() { exists(Call call | call.getCallee().getSourceDeclaration() = this | result.asExpr().(Argument).getCall() = call or result.(ArgumentNode).getCall().asCall() = call ) } /** Gets a node that is an output from a call to this API. */ private DataFlow::Node getAnOutput() { exists(Call call | call.getCallee().getSourceDeclaration() = this | result.asExpr() = call or result.(DataFlow::PostUpdateNode).getPreUpdateNode().(ArgumentNode).getCall().asCall() = call ) } /** Holds if this API has a supported summary. */ pragma[nomagic] predicate hasSummary() { this = any(SummarizedCallable sc).asCallable() or TaintTracking::localAdditionalTaintStep(this.getAnInput(), _, _) } pragma[nomagic] predicate isSource() { this.getAnOutput() instanceof ApiSources::SourceNode } /** Holds if this API is a known sink. */ pragma[nomagic] predicate isSink() { this.getAnInput() instanceof ApiSinks::SinkNode } /** Holds if this API is a known neutral. */ pragma[nomagic] predicate isNeutral() { this = any(FlowSummaryImpl::Public::NeutralCallable n).asCallable() } /** * Holds if this API is supported by existing CodeQL libraries, that is, it is either a * recognized source, sink or neutral or it has a flow summary. */ predicate isSupported() { this.hasSummary() or this.isSource() or this.isSink() or this.isNeutral() } } /** * Gets the limit for the number of results produced by a telemetry query. */ int resultLimit() { result = 100 } /** * Holds if it is relevant to count usages of `api`. */ signature predicate relevantApi(ExternalApi api); /** * Given a predicate to count relevant API usages, this module provides a predicate * for restricting the number or returned results based on a certain limit. */ module Results<relevantApi/1 getRelevantUsages> { private int getUsages(string apiName) { result = strictcount(Call c, ExternalApi api | c.getCallee().getSourceDeclaration() = api and not c.getFile() instanceof GeneratedFile and apiName = api.getApiName() and getRelevantUsages(api) ) } private int getOrder(string apiInfo) { apiInfo = rank[result](string info, int usages | usages = getUsages(info) | info order by usages desc, info ) } /** * Holds if there exists an API with `apiName` that is being used `usages` times * and if it is in the top results (guarded by resultLimit). */ predicate restrict(string apiName, int usages) { usages = getUsages(apiName) and getOrder(apiName) <= resultLimit() } } |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |