mirror of
https://github.com/github/codeql.git
synced 2026-04-23 15:55:18 +02:00
C#: Use correct names for generic types/methods in model editor queries
This commit is contained in:
@@ -18,6 +18,6 @@ where
|
||||
usage = aUsage(endpoint) and
|
||||
type = supportedType(endpoint) and
|
||||
classification = methodClassification(usage)
|
||||
select usage, endpoint.getNamespace(), endpoint.getTypeName(), endpoint.getName(),
|
||||
select usage, endpoint.getNamespace(), endpoint.getTypeName(), endpoint.getMethodName(),
|
||||
endpoint.getParameterTypes(), supported, endpoint.dllName(), endpoint.dllVersion(), type,
|
||||
classification
|
||||
|
||||
@@ -14,5 +14,5 @@ from PublicEndpointFromSource endpoint, boolean supported, string type
|
||||
where
|
||||
supported = isSupported(endpoint) and
|
||||
type = supportedType(endpoint)
|
||||
select endpoint, endpoint.getNamespace(), endpoint.getTypeName(), endpoint.getName(),
|
||||
select endpoint, endpoint.getNamespace(), endpoint.getTypeName(), endpoint.getMethodName(),
|
||||
endpoint.getParameterTypes(), supported, endpoint.getFile().getBaseName(), type
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/** Provides classes and predicates related to handling APIs for the VS Code extension. */
|
||||
|
||||
private import csharp
|
||||
private import semmle.code.csharp.commons.QualifiedName
|
||||
private import semmle.code.csharp.dataflow.FlowSummary
|
||||
private import semmle.code.csharp.dataflow.internal.FlowSummaryImpl as FlowSummaryImpl
|
||||
private import semmle.code.csharp.dataflow.internal.ExternalFlow
|
||||
@@ -34,7 +35,17 @@ class Endpoint extends Callable {
|
||||
* Gets the unbound type name of this endpoint.
|
||||
*/
|
||||
bindingset[this]
|
||||
string getTypeName() { result = nestedName(this.getDeclaringType().getUnboundDeclaration()) }
|
||||
string getTypeName() {
|
||||
result = qualifiedTypeName(this.getNamespace(), this.getDeclaringType().getUnboundDeclaration())
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the qualified method name of this endpoint.
|
||||
*/
|
||||
bindingset[this]
|
||||
string getMethodName() {
|
||||
result = qualifiedCallableName(this.getNamespace(), this.getTypeName(), this)
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the parameter types of this endpoint.
|
||||
@@ -107,15 +118,25 @@ string methodClassification(Call method) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the nested name of the type `t`.
|
||||
*
|
||||
* If the type is not a nested type, the result is the same as `getName()`.
|
||||
* Otherwise the name of the nested type is prefixed with a `+` and appended to
|
||||
* the name of the enclosing type, which might be a nested type as well.
|
||||
* Gets the fully qualified name of the type `t`.
|
||||
*/
|
||||
private string nestedName(Type t) {
|
||||
not exists(t.getDeclaringType().getUnboundDeclaration()) and
|
||||
result = t.getName()
|
||||
or
|
||||
nestedName(t.getDeclaringType().getUnboundDeclaration()) + "+" + t.getName() = result
|
||||
private string qualifiedTypeName(string namespace, Type t) {
|
||||
exists(string type | QN::hasQualifiedName(t, namespace, type) | result = type)
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the fully qualified name of the callable `c`.
|
||||
*/
|
||||
private string qualifiedCallableName(string namespace, string type, Callable c) {
|
||||
exists(string name | QN::hasQualifiedName(c, namespace, type, name) | result = name)
|
||||
}
|
||||
|
||||
private module QualifiedNameInput implements QualifiedNameInputSig {
|
||||
string getUnboundGenericSuffix(UnboundGeneric ug) {
|
||||
result =
|
||||
"<" + strictconcat(int i, string s | s = ug.getTypeParameter(i).getName() | s, "," order by i)
|
||||
+ ">"
|
||||
}
|
||||
}
|
||||
|
||||
private module QN = QualifiedName<QualifiedNameInput>;
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
| PublicClass.cs:40:19:40:29 | sourceStuff | GitHub.CodeQL | PublicClass | sourceStuff | () | true | PublicClass.cs | source |
|
||||
| PublicClass.cs:45:17:45:25 | sinkStuff | GitHub.CodeQL | PublicClass | sinkStuff | (System.String) | true | PublicClass.cs | sink |
|
||||
| PublicClass.cs:50:17:50:28 | neutralStuff | GitHub.CodeQL | PublicClass | neutralStuff | (System.String) | true | PublicClass.cs | neutral |
|
||||
| PublicGenericClass.cs:7:17:7:21 | stuff | GitHub.CodeQL | PublicGenericClass`2 | stuff | (T) | false | PublicGenericClass.cs | |
|
||||
| PublicGenericClass.cs:12:17:12:26 | stuff2`1 | GitHub.CodeQL | PublicGenericClass`2 | stuff2`1 | (T2) | false | PublicGenericClass.cs | |
|
||||
| PublicGenericClass.cs:17:18:17:36 | summaryStuff`1 | GitHub.CodeQL | PublicGenericClass`2 | summaryStuff`1 | (TNode) | true | PublicGenericClass.cs | summary |
|
||||
| PublicGenericInterface.cs:7:10:7:14 | stuff | GitHub.CodeQL | PublicGenericInterface`1 | stuff | (T) | false | PublicGenericInterface.cs | |
|
||||
| PublicGenericInterface.cs:9:10:9:19 | stuff2`1 | GitHub.CodeQL | PublicGenericInterface`1 | stuff2`1 | (T2) | false | PublicGenericInterface.cs | |
|
||||
| PublicGenericInterface.cs:11:17:11:27 | staticStuff | GitHub.CodeQL | PublicGenericInterface`1 | staticStuff | (System.String) | false | PublicGenericInterface.cs | |
|
||||
| PublicGenericClass.cs:7:17:7:21 | stuff | GitHub.CodeQL | PublicGenericClass<T,T2> | stuff | (T) | false | PublicGenericClass.cs | |
|
||||
| PublicGenericClass.cs:12:17:12:26 | stuff2`1 | GitHub.CodeQL | PublicGenericClass<T,T2> | stuff2<T2> | (T2) | false | PublicGenericClass.cs | |
|
||||
| PublicGenericClass.cs:17:18:17:36 | summaryStuff`1 | GitHub.CodeQL | PublicGenericClass<T,T2> | summaryStuff<TNode> | (TNode) | true | PublicGenericClass.cs | summary |
|
||||
| PublicGenericInterface.cs:7:10:7:14 | stuff | GitHub.CodeQL | PublicGenericInterface<T> | stuff | (T) | false | PublicGenericInterface.cs | |
|
||||
| PublicGenericInterface.cs:9:10:9:19 | stuff2`1 | GitHub.CodeQL | PublicGenericInterface<T> | stuff2<T2> | (T2) | false | PublicGenericInterface.cs | |
|
||||
| PublicGenericInterface.cs:11:17:11:27 | staticStuff | GitHub.CodeQL | PublicGenericInterface<T> | staticStuff | (System.String) | false | PublicGenericInterface.cs | |
|
||||
| PublicInterface.cs:7:10:7:14 | stuff | GitHub.CodeQL | PublicInterface | stuff | (System.String) | false | PublicInterface.cs | |
|
||||
| PublicInterface.cs:9:29:9:31 | get_PublicProperty | GitHub.CodeQL | PublicInterface | get_PublicProperty | () | false | PublicInterface.cs | |
|
||||
| PublicInterface.cs:9:34:9:36 | set_PublicProperty | GitHub.CodeQL | PublicInterface | set_PublicProperty | (System.String) | false | PublicInterface.cs | |
|
||||
|
||||
Reference in New Issue
Block a user