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/python/ql/lib/modeling/ModelEditor.qll at codeql-cli/v2.19.1 · github/codeql Expand file tree/ Copy pathModelEditor.qllMore file actions 246 lines (208 loc) · 8.22 KB / Copy pathModelEditor.qllFile metadata and controls246 lines (208 loc) · 8.22 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 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 /** Provides classes and predicates related to handling APIs for the VS Code extension. */ private import python private import semmle.python.frameworks.data.ModelsAsData private import semmle.python.frameworks.data.internal.ApiGraphModelsExtensions private import semmle.python.dataflow.new.internal.DataFlowDispatch as DP private import Util as Util /** * An string describing the kind of source code element being modeled. * * See `EndPoint`. */ class EndpointKind extends string { EndpointKind() { this in ["Function", "InstanceMethod", "ClassMethod", "StaticMethod", "InitMethod", "Class"] } } /** * An element of the source code to be modeled. * * See `EndPointKind` for the possible kinds of elements. */ abstract class Endpoint instanceof Util::RelevantScope { string namespace; string type; string name; Endpoint() { exists(string scopePath, string path, int pathIndex | scopePath = Util::computeScopePath(this) and pathIndex = scopePath.indexOf(".", 0, 0) | namespace = scopePath.prefix(pathIndex) and path = scopePath.suffix(pathIndex + 1) and ( exists(int nameIndex | nameIndex = max(path.indexOf(".")) | type = path.prefix(nameIndex) and name = path.suffix(nameIndex + 1) ) or not exists(path.indexOf(".")) and type = "" and name = path ) ) } /** Gets the namespace for this endpoint. This will typically be the package in which it is found. */ string getNamespace() { result = namespace } /** Gets hte basename of the file where this endpoint is found. */ string getFileName() { result = super.getLocation().getFile().getBaseName() } /** Gets a string representation of this endpoint. */ string toString() { result = super.toString() } /** Gets the location of this endpoint. */ Location getLocation() { result = super.getLocation() } /** Gets the name of the class in which this endpoint is found, or the empty string if it is not found inside a class. */ string getClass() { result = type } /** * Gets the name of the endpoint if it is not a class, or the empty string if it is a class * * If this endpoint is a class, the class name can be obtained via `getType`. */ string getFunctionName() { result = name } /** * Gets a string representation of the parameters of this endpoint. * * The string follows a specific format: * - Normal parameters(where arguments can be passed as either positional or keyword) are listed in order, separated by commas. * - Keyword-only parameters are listed in order, separated by commas, each followed by a colon. * - In the future, positional-only parameters will be listed in order, separated by commas, each followed by a slash. */ abstract string getParameters(); /** * Gets a boolean that is true iff this endpoint is supported by existing modeling. * * The check only takes Models as Data extension models into account. */ abstract boolean getSupportedStatus(); /** * Gets a string that describes the type of support detected this endpoint. * * The string can be one of the following: * - "source" if this endpoint is a known source. * - "sink" if this endpoint is a known sink. * - "summary" if this endpoint has a flow summary. * - "neutral" if this endpoint is a known neutral. * - "" if this endpoint is not detected as supported. */ abstract string getSupportedType(); /** Gets the kind of this endpoint. See `EndPointKind`. */ abstract EndpointKind getKind(); } private predicate sourceModelPath(string type, string path) { sourceModel(type, path, _, _) } module FindSourceModel = Util::FindModel<sourceModelPath/2>; private predicate sinkModelPath(string type, string path) { sinkModel(type, path, _, _) } module FindSinkModel = Util::FindModel<sinkModelPath/2>; private predicate summaryModelPath(string type, string path) { summaryModel(type, path, _, _, _, _) } module FindSummaryModel = Util::FindModel<summaryModelPath/2>; private predicate neutralModelPath(string type, string path) { neutralModel(type, path, _) } module FindNeutralModel = Util::FindModel<neutralModelPath/2>; /** * A callable function or method from source code. */ class FunctionEndpoint extends Endpoint instanceof Function { /** * Gets the parameter types of this endpoint. */ override string getParameters() { // For now, return the names of positional and keyword parameters. We don't always have type information, so we can't return type names. // We don't yet handle splat params or dict splat params. // // In Python, there are three types of parameters: // 1. Positional-only parameters: These are parameters that can only be passed by position and not by keyword. // 2. Positional-or-keyword parameters: These are parameters that can be passed by position or by keyword. // 3. Keyword-only parameters: These are parameters that can only be passed by keyword. // // The syntax for defining these parameters is as follows: // ```python // def f(a, /, b, *, c): // pass // ``` // In this example, `a` is a positional-only parameter, `b` is a positional-or-keyword parameter, and `c` is a keyword-only parameter. // // We handle positional-only parameters by adding a "/" to the parameter name, reminiscient of the syntax above. // Note that we don't yet have information about positional-only parameters. // We handle keyword-only parameters by adding a ":" to the parameter name, to be consistent with the MaD syntax and the other languages. exists(int nrPosOnly, Function f | f = this and nrPosOnly = f.getPositionalParameterCount() | result = "(" + concat(string key, string value | // TODO: Once we have information about positional-only parameters: // Handle positional-only parameters by adding a "/" value = any(int i | i.toString() = key | f.getArgName(i)) or exists(Name param | param = f.getAKeywordOnlyArg() | param.getId() = key and value = key + ":" ) | value, "," order by key ) + ")" ) } /** Holds if this API has a supported summary. */ pragma[nomagic] predicate hasSummary() { FindSummaryModel::hasModel(this) } /** Holds if this API is a known source. */ pragma[nomagic] predicate isSource() { FindSourceModel::hasModel(this) } /** Holds if this API is a known sink. */ pragma[nomagic] predicate isSink() { FindSinkModel::hasModel(this) } /** Holds if this API is a known neutral. */ pragma[nomagic] predicate isNeutral() { FindNeutralModel::hasModel(this) } /** * 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() } override boolean getSupportedStatus() { if this.isSupported() then result = true else result = false } override string getSupportedType() { this.isSink() and result = "sink" or this.isSource() and result = "source" or this.hasSummary() and result = "summary" or this.isNeutral() and result = "neutral" or not this.isSupported() and result = "" } override EndpointKind getKind() { if this.(Function).isMethod() then result = this.methodKind() or not exists(this.methodKind()) and result = "InstanceMethod" else result = "Function" } private EndpointKind methodKind() { this.(Function).isMethod() and ( DP::isClassmethod(this) and result = "ClassMethod" or DP::isStaticmethod(this) and result = "StaticMethod" or this.(Function).isInitMethod() and result = "InitMethod" ) } } /** * A class from source code. */ class ClassEndpoint extends Endpoint instanceof Class { override string getClass() { result = type + "." + name } override string getFunctionName() { result = "" } override string getParameters() { result = "" } override boolean getSupportedStatus() { result = false } override string getSupportedType() { result = "" } override EndpointKind getKind() { result = "Class" } } |
| 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. |