mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
C#: Address review comments.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
---
|
||||
category: minorAnalysis
|
||||
---
|
||||
* Deprecate `hasQualifiedName/1`. Use `hasQualifiedName/2` or `hasQualifiedName/3` instead.
|
||||
* `Element::hasQualifiedName/1` has been deprecated. Use `hasQualifiedName/2` or `hasQualifiedName/3` instead.
|
||||
@@ -21,7 +21,6 @@ import semmle.code.csharp.Using
|
||||
import semmle.code.csharp.Variable
|
||||
import semmle.code.csharp.XML
|
||||
import semmle.code.csharp.Preprocessor
|
||||
import semmle.code.csharp.Printing
|
||||
import semmle.code.csharp.exprs.Access
|
||||
import semmle.code.csharp.exprs.ArithmeticOperation
|
||||
import semmle.code.csharp.exprs.Assignment
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
import csharp
|
||||
private import semmle.code.csharp.commons.QualifiedName
|
||||
|
||||
/**
|
||||
* An ASP.NET program element. Either an attribute (`AspAttribute`), an open
|
||||
@@ -184,9 +185,9 @@ class PageDirective extends AspDirective {
|
||||
* Gets the 'CodeBehind' class from which this page inherits.
|
||||
*/
|
||||
ValueOrRefType getInheritedType() {
|
||||
exists(string qualifier, string name |
|
||||
result.hasQualifiedName(qualifier, name) and
|
||||
printQualifiedName(qualifier, name) = this.getInheritedTypeQualifiedName()
|
||||
exists(string namespace, string type |
|
||||
result.hasQualifiedName(namespace, type) and
|
||||
splitQualifiedName(this.getInheritedTypeQualifiedName(), namespace, type)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
private import CIL
|
||||
private import csharp as CS
|
||||
private import semmle.code.csharp.commons.QualifiedName
|
||||
|
||||
private newtype ConsistencyCheck =
|
||||
MissingEntityCheck() or
|
||||
@@ -484,12 +485,11 @@ class InvalidOverride extends MethodViolation {
|
||||
}
|
||||
|
||||
override string getMessage() {
|
||||
exists(string qualifier, string name |
|
||||
base.getDeclaringType().hasQualifiedName(qualifier, name)
|
||||
exists(string namespace, string type |
|
||||
base.getDeclaringType().hasQualifiedName(namespace, type)
|
||||
|
|
||||
result =
|
||||
"Overridden method from " + CS::printQualifiedName(qualifier, name) +
|
||||
" is not in a base type"
|
||||
"Overridden method from " + printQualifiedName(namespace, type) + " is not in a base type"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
import CIL
|
||||
private import dotnet
|
||||
private import semmle.code.csharp.Printing
|
||||
private import semmle.code.csharp.commons.QualifiedName
|
||||
|
||||
/**
|
||||
* Something that contains other types.
|
||||
@@ -51,10 +51,10 @@ class Type extends DotNet::Type, Declaration, TypeContainer, @cil_type {
|
||||
*/
|
||||
Type getUnboundType() { cil_type(this, _, _, _, result) }
|
||||
|
||||
override predicate hasQualifiedName(string qualifier, string name) {
|
||||
override predicate hasQualifiedName(string namespace, string name) {
|
||||
name = this.getName() and
|
||||
exists(string pqualifier, string pname | this.getParent().hasQualifiedName(pqualifier, pname) |
|
||||
qualifier = printQualifiedName(pqualifier, pname)
|
||||
exists(string pnamespace, string pname | this.getParent().hasQualifiedName(pnamespace, pname) |
|
||||
namespace = printQualifiedName(pnamespace, pname)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ class Variable extends DotNet::Variable, Declaration, DataFlowNode, @cil_variabl
|
||||
|
||||
/** A stack variable. Either a local variable (`LocalVariable`) or a parameter (`Parameter`). */
|
||||
class StackVariable extends Variable, @cil_stack_variable {
|
||||
override predicate hasQualifiedName(string qualifier, string name) { none() }
|
||||
override predicate hasQualifiedName(string namespace, string name) { none() }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,6 +7,7 @@ import Member
|
||||
import Stmt
|
||||
import Type
|
||||
import exprs.Call
|
||||
private import commons.QualifiedName
|
||||
private import dotnet
|
||||
private import semmle.code.csharp.ExprOrStmtParent
|
||||
private import semmle.code.csharp.metrics.Complexity
|
||||
@@ -455,8 +456,8 @@ class Operator extends Callable, Member, Attributable, @operator {
|
||||
|
||||
override Parameter getRawParameter(int i) { result = this.getParameter(i) }
|
||||
|
||||
override predicate hasQualifiedName(string qualifier, string name) {
|
||||
super.hasQualifiedName(qualifier, _) and
|
||||
override predicate hasQualifiedName(string namespace, string name) {
|
||||
super.hasQualifiedName(namespace, _) and
|
||||
name = this.getFunctionName()
|
||||
}
|
||||
|
||||
@@ -1000,10 +1001,10 @@ class LocalFunction extends Callable, Modifiable, Attributable, @local_function
|
||||
|
||||
override Callable getEnclosingCallable() { result = this.getStatement().getEnclosingCallable() }
|
||||
|
||||
override predicate hasQualifiedName(string qualifier, string name) {
|
||||
exists(string cqualifier, string type |
|
||||
this.getEnclosingCallable().hasQualifiedName(cqualifier, type) and
|
||||
qualifier = printQualifiedName(cqualifier, type)
|
||||
override predicate hasQualifiedName(string namespace, string name) {
|
||||
exists(string cnamespace, string type |
|
||||
this.getEnclosingCallable().hasQualifiedName(cnamespace, type) and
|
||||
namespace = printQualifiedName(cnamespace, type)
|
||||
) and
|
||||
name = this.getName()
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
import Location
|
||||
import Namespace
|
||||
private import commons.QualifiedName
|
||||
private import dotnet
|
||||
private import TypeRef
|
||||
|
||||
@@ -99,9 +100,9 @@ private string getTypeArgumentsNames(ConstructedGeneric cg) {
|
||||
|
||||
bindingset[t]
|
||||
private string getFullName(Type t) {
|
||||
exists(string qualifier, string name |
|
||||
t.hasQualifiedName(qualifier, name) and
|
||||
result = printQualifiedName(qualifier, name)
|
||||
exists(string namespace, string name |
|
||||
t.hasQualifiedName(namespace, name) and
|
||||
result = printQualifiedName(namespace, name)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -158,15 +159,15 @@ class UnboundGenericType extends ValueOrRefType, UnboundGeneric {
|
||||
result = this.getUndecoratedName() + "<" + getTypeParameterCommas(this) + ">"
|
||||
}
|
||||
|
||||
final override predicate hasQualifiedName(string qualifier, string name) {
|
||||
final override predicate hasQualifiedName(string namespace, string name) {
|
||||
exists(string name0 | name = name0 + "<" + getTypeParameterCommas(this) + ">" |
|
||||
exists(string enclosing |
|
||||
this.getDeclaringType().hasQualifiedName(qualifier, enclosing) and
|
||||
this.getDeclaringType().hasQualifiedName(namespace, enclosing) and
|
||||
name0 = enclosing + "+" + this.getUndecoratedName()
|
||||
)
|
||||
or
|
||||
not exists(this.getDeclaringType()) and
|
||||
qualifier = this.getNamespace().getFullName() and
|
||||
namespace = this.getNamespace().getFullName() and
|
||||
name0 = this.getUndecoratedName()
|
||||
)
|
||||
}
|
||||
@@ -236,8 +237,8 @@ class TypeParameter extends DotNet::TypeParameter, Type, @type_parameter {
|
||||
/** Gets the generic that defines this type parameter. */
|
||||
UnboundGeneric getGeneric() { type_parameters(this, _, result, _) }
|
||||
|
||||
final override predicate hasQualifiedName(string qualifier, string name) {
|
||||
qualifier = "" and
|
||||
final override predicate hasQualifiedName(string namespace, string name) {
|
||||
namespace = "" and
|
||||
name = this.getName()
|
||||
}
|
||||
|
||||
@@ -423,15 +424,15 @@ class ConstructedType extends ValueOrRefType, ConstructedGeneric {
|
||||
result = this.getUndecoratedName() + "<" + getTypeArgumentsNames(this) + ">"
|
||||
}
|
||||
|
||||
final override predicate hasQualifiedName(string qualifier, string name) {
|
||||
final override predicate hasQualifiedName(string namespace, string name) {
|
||||
exists(string name0 | name = name0 + "<" + getTypeArgumentsQualifiedNames(this) + ">" |
|
||||
exists(string enclosing |
|
||||
this.getDeclaringType().hasQualifiedName(qualifier, enclosing) and
|
||||
this.getDeclaringType().hasQualifiedName(namespace, enclosing) and
|
||||
name0 = enclosing + "+" + this.getUndecoratedName()
|
||||
)
|
||||
or
|
||||
not exists(this.getDeclaringType()) and
|
||||
qualifier = this.getNamespace().getFullName() and
|
||||
namespace = this.getNamespace().getFullName() and
|
||||
name0 = this.getUndecoratedName()
|
||||
)
|
||||
}
|
||||
@@ -601,8 +602,8 @@ class ConstructedMethod extends Method, ConstructedGeneric {
|
||||
result = this.getUndecoratedName() + "<" + getTypeArgumentsNames(this) + ">"
|
||||
}
|
||||
|
||||
override predicate hasQualifiedName(string qualifier, string type, string name) {
|
||||
this.getDeclaringType().hasQualifiedName(qualifier, type) and
|
||||
override predicate hasQualifiedName(string namespace, string type, string name) {
|
||||
this.getDeclaringType().hasQualifiedName(namespace, type) and
|
||||
name = this.getUndecoratedName() + "<" + getTypeArgumentsQualifiedNames(this) + ">"
|
||||
}
|
||||
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
/**
|
||||
* Provides predicates to pretty-print a C# qualified name.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns the concatenation of `qualifier` and `name`, separated by a dot.
|
||||
*/
|
||||
bindingset[qualifier, name]
|
||||
string printQualifiedName(string qualifier, string name) {
|
||||
if qualifier = "" then result = name else result = qualifier + "." + name
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the concatenation of `qualifier`, `type` and `name`, separated by a dot.
|
||||
*/
|
||||
bindingset[qualifier, type, name]
|
||||
string printQualifiedName(string qualifier, string type, string name) {
|
||||
result = printQualifiedName(qualifier, type) + "." + name
|
||||
}
|
||||
@@ -57,19 +57,19 @@ private predicate isObjectClass(Class c) { c instanceof ObjectType }
|
||||
*/
|
||||
class ValueOrRefType extends DotNet::ValueOrRefType, Type, Attributable, @value_or_ref_type {
|
||||
/**
|
||||
* Holds if this type has the qualified name `qualifier`.`name`.
|
||||
* Holds if this type has the qualified name `namespace`.`name`.
|
||||
*
|
||||
* For example the class `System.IO.IOException` has
|
||||
* `qualifier`=`System.IO` and `name`=`IOException`.
|
||||
* `namespace`=`System.IO` and `name`=`IOException`.
|
||||
*/
|
||||
override predicate hasQualifiedName(string qualifier, string name) {
|
||||
override predicate hasQualifiedName(string namespace, string name) {
|
||||
exists(string enclosing |
|
||||
this.getDeclaringType().hasQualifiedName(qualifier, enclosing) and
|
||||
this.getDeclaringType().hasQualifiedName(namespace, enclosing) and
|
||||
name = enclosing + "+" + this.getUndecoratedName()
|
||||
)
|
||||
or
|
||||
not exists(this.getDeclaringType()) and
|
||||
qualifier = this.getNamespace().getFullName() and
|
||||
namespace = this.getNamespace().getFullName() and
|
||||
name = this.getUndecoratedName()
|
||||
}
|
||||
|
||||
@@ -398,8 +398,8 @@ class NonNestedType extends ValueOrRefType {
|
||||
* The `void` type.
|
||||
*/
|
||||
class VoidType extends DotNet::ValueOrRefType, Type, @void_type {
|
||||
override predicate hasQualifiedName(string qualifier, string name) {
|
||||
qualifier = "System" and
|
||||
override predicate hasQualifiedName(string namespace, string name) {
|
||||
namespace = "System" and
|
||||
name = "Void"
|
||||
}
|
||||
|
||||
@@ -1007,8 +1007,8 @@ class NullableType extends ValueType, DotNet::ConstructedGeneric, @nullable_type
|
||||
result = "Nullable<" + this.getUnderlyingType().getName() + ">"
|
||||
}
|
||||
|
||||
final override predicate hasQualifiedName(string qualifier, string name) {
|
||||
qualifier = "System" and
|
||||
final override predicate hasQualifiedName(string namespace, string name) {
|
||||
namespace = "System" and
|
||||
name = "Nullable<" + this.getUnderlyingType().getQualifiedName() + ">"
|
||||
}
|
||||
}
|
||||
@@ -1076,9 +1076,9 @@ class ArrayType extends DotNet::ArrayType, RefType, @array_type {
|
||||
result = this.getElementType().getALocation()
|
||||
}
|
||||
|
||||
final override predicate hasQualifiedName(string qualifier, string name) {
|
||||
final override predicate hasQualifiedName(string namespace, string name) {
|
||||
exists(Type elementType, string name0 |
|
||||
elementType.hasQualifiedName(qualifier, name0) and
|
||||
elementType.hasQualifiedName(namespace, name0) and
|
||||
name = name0 + this.getDimensionString(elementType)
|
||||
)
|
||||
}
|
||||
@@ -1106,9 +1106,9 @@ class PointerType extends DotNet::PointerType, Type, @pointer_type {
|
||||
|
||||
override string getAPrimaryQlClass() { result = "PointerType" }
|
||||
|
||||
final override predicate hasQualifiedName(string qualifier, string name) {
|
||||
final override predicate hasQualifiedName(string namespace, string name) {
|
||||
exists(string name0 |
|
||||
this.getReferentType().hasQualifiedName(qualifier, name0) and
|
||||
this.getReferentType().hasQualifiedName(namespace, name0) and
|
||||
name = name0 + "*"
|
||||
)
|
||||
}
|
||||
@@ -1190,8 +1190,8 @@ class TupleType extends ValueType, @tuple_type {
|
||||
|
||||
override Type getChild(int i) { result = this.getUnderlyingType().getChild(i) }
|
||||
|
||||
final override predicate hasQualifiedName(string qualifier, string name) {
|
||||
this.getUnderlyingType().hasQualifiedName(qualifier, name)
|
||||
final override predicate hasQualifiedName(string namespace, string name) {
|
||||
this.getUnderlyingType().hasQualifiedName(namespace, name)
|
||||
}
|
||||
|
||||
override string getAPrimaryQlClass() { result = "TupleType" }
|
||||
|
||||
@@ -71,7 +71,7 @@ class LocalScopeVariable extends Variable, @local_scope_variable {
|
||||
*/
|
||||
predicate isRef() { none() }
|
||||
|
||||
override predicate hasQualifiedName(string qualifier, string name) { none() }
|
||||
override predicate hasQualifiedName(string namespace, string name) { none() }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
34
csharp/ql/lib/semmle/code/csharp/commons/QualifiedName.qll
Normal file
34
csharp/ql/lib/semmle/code/csharp/commons/QualifiedName.qll
Normal file
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* Provides predicates related to C# qualified name.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns the concatenation of `qualifier` and `name`, separated by a dot.
|
||||
*/
|
||||
bindingset[namespace, name]
|
||||
string printQualifiedName(string namespace, string name) {
|
||||
if namespace = "" then result = name else result = namespace + "." + name
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the concatenation of `qualifier`, `type` and `name`, separated by a dot.
|
||||
*/
|
||||
bindingset[namespace, type, name]
|
||||
string printQualifiedName(string namespace, string type, string name) {
|
||||
result = printQualifiedName(namespace, type) + "." + name
|
||||
}
|
||||
|
||||
private string getNameSplitter() { result = "(.*)\\.([^\\.]+)$" }
|
||||
|
||||
/**
|
||||
*/
|
||||
bindingset[qualifiedName]
|
||||
predicate splitQualifiedName(string qualifiedName, string qualifier, string name) {
|
||||
if qualifiedName.regexpMatch(getNameSplitter())
|
||||
then
|
||||
qualifier = qualifiedName.regexpCapture(getNameSplitter(), 1) and
|
||||
name = qualifiedName.regexpCapture(getNameSplitter(), 2)
|
||||
else (
|
||||
qualifier = "" and name = qualifiedName
|
||||
)
|
||||
}
|
||||
@@ -9,7 +9,7 @@ private import semmle.code.csharp.frameworks.system.Data
|
||||
module Dapper {
|
||||
/** The namespace `Dapper`. */
|
||||
class DapperNamespace extends Namespace {
|
||||
DapperNamespace() { this.hasQualifiedName("", "Dapper") }
|
||||
DapperNamespace() { this.getFullName() = "Dapper" }
|
||||
}
|
||||
|
||||
/** A class in `Dapper`. */
|
||||
|
||||
@@ -37,11 +37,7 @@ private predicate isNotMapped(Attributable a) {
|
||||
module EntityFramework {
|
||||
/** An EF6 or EFCore namespace. */
|
||||
class EFNamespace extends Namespace {
|
||||
EFNamespace() {
|
||||
this.hasQualifiedName("Microsoft", "EntityFrameworkCore")
|
||||
or
|
||||
this.hasQualifiedName("System.Data", "Entity")
|
||||
}
|
||||
EFNamespace() { this.getFullName() = ["Microsoft.EntityFrameworkCore", "System.Data.Entity"] }
|
||||
}
|
||||
|
||||
/** A taint source where the data has come from a mapped property stored in the database. */
|
||||
|
||||
@@ -8,7 +8,7 @@ import csharp
|
||||
module JsonNET {
|
||||
/** The namespace `Newtonsoft.Json`. */
|
||||
class JsonNETNamespace extends Namespace {
|
||||
JsonNETNamespace() { this.hasQualifiedName("Newtonsoft", "Json") }
|
||||
JsonNETNamespace() { this.getFullName() = "Newtonsoft.Json" }
|
||||
}
|
||||
|
||||
/** A class in `Newtonsoft.Json`. */
|
||||
|
||||
@@ -4,7 +4,7 @@ import csharp
|
||||
|
||||
/** The `Moq.Language` Namespace. */
|
||||
class MoqLanguageNamespace extends Namespace {
|
||||
MoqLanguageNamespace() { this.hasQualifiedName("Moq", "Language") }
|
||||
MoqLanguageNamespace() { this.getFullName() = "Moq.Language" }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import csharp
|
||||
import semmle.code.csharp.frameworks.Test
|
||||
private import semmle.code.csharp.commons.QualifiedName
|
||||
|
||||
/** A class that is an NUnit test fixture */
|
||||
class NUnitFixture extends TestClass {
|
||||
@@ -14,19 +15,6 @@ class NUnitFixture extends TestClass {
|
||||
}
|
||||
}
|
||||
|
||||
private string getNameSplitter() { result = "(.*)\\.([^\\.]+)$" }
|
||||
|
||||
bindingset[name]
|
||||
private predicate splitExceptionName(string name, string namespace, string type) {
|
||||
if name.regexpMatch(getNameSplitter())
|
||||
then
|
||||
namespace = name.regexpCapture(getNameSplitter(), 1) and
|
||||
type = name.regexpCapture(getNameSplitter(), 2)
|
||||
else (
|
||||
namespace = "" and type = name
|
||||
)
|
||||
}
|
||||
|
||||
/** An NUnit test method. */
|
||||
class NUnitTestMethod extends TestMethod {
|
||||
NUnitTestMethod() {
|
||||
@@ -54,7 +42,7 @@ class NUnitTestMethod extends TestMethod {
|
||||
then
|
||||
exists(string namespace, string type |
|
||||
result.hasQualifiedName(namespace, type) and
|
||||
splitExceptionName(expected.getArgument(0).getValue(), namespace, type)
|
||||
splitQualifiedName(expected.getArgument(0).getValue(), namespace, type)
|
||||
)
|
||||
else result = expected.getArgument(0).(TypeofExpr).getTypeAccess().getTarget()
|
||||
)
|
||||
|
||||
@@ -5,7 +5,7 @@ import semmle.code.csharp.frameworks.Test
|
||||
|
||||
/** The `Microsoft.VisualStudio.TestTools.UnitTesting` namespace. */
|
||||
class VSTestNamespace extends Namespace {
|
||||
VSTestNamespace() { this.hasQualifiedName("Microsoft.VisualStudio.TestTools", "UnitTesting") }
|
||||
VSTestNamespace() { this.getFullName() = "Microsoft.VisualStudio.TestTools.UnitTesting" }
|
||||
}
|
||||
|
||||
/** A class that contains test methods. */
|
||||
|
||||
@@ -5,7 +5,7 @@ import semmle.code.csharp.frameworks.Test
|
||||
|
||||
/** The `Xunit` namespace. */
|
||||
class XUnitNamespace extends Namespace {
|
||||
XUnitNamespace() { this.hasQualifiedName("", "Xunit") }
|
||||
XUnitNamespace() { this.getFullName() = "Xunit" }
|
||||
}
|
||||
|
||||
/** An xUnit test attribute. */
|
||||
|
||||
@@ -4,14 +4,14 @@
|
||||
|
||||
import Element
|
||||
import Type
|
||||
private import semmle.code.csharp.Printing
|
||||
private import semmle.code.csharp.commons.QualifiedName
|
||||
|
||||
/** A declaration. */
|
||||
class Declaration extends NamedElement, @dotnet_declaration {
|
||||
override predicate hasQualifiedName(string qualifier, string name) {
|
||||
exists(string dqualifier, string dname |
|
||||
this.getDeclaringType().hasQualifiedName(dqualifier, dname) and
|
||||
qualifier = printQualifiedName(dqualifier, dname)
|
||||
override predicate hasQualifiedName(string namespace, string name) {
|
||||
exists(string dnamespace, string dname |
|
||||
this.getDeclaringType().hasQualifiedName(dnamespace, dname) and
|
||||
namespace = printQualifiedName(dnamespace, dname)
|
||||
) and
|
||||
name = this.getName()
|
||||
}
|
||||
@@ -85,8 +85,8 @@ class Member extends Declaration, @dotnet_member {
|
||||
* with qualifier `qualifier`
|
||||
*/
|
||||
cached
|
||||
predicate hasQualifiedName(string qualifier, string type, string name) {
|
||||
this.getDeclaringType().hasQualifiedName(qualifier, type) and
|
||||
predicate hasQualifiedName(string namespace, string type, string name) {
|
||||
this.getDeclaringType().hasQualifiedName(namespace, type) and
|
||||
name = this.getName()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ class NamedElement extends Element, @dotnet_named_element {
|
||||
}
|
||||
|
||||
/**
|
||||
* DEPRECATED: Use hasQualifiedName instead.
|
||||
* DEPRECATED: Use `hasQualifiedName/2` instead.
|
||||
* Holds if this element has qualified name `qualifiedName`, for example
|
||||
* `System.Console.WriteLine`.
|
||||
*/
|
||||
@@ -107,8 +107,8 @@ class NamedElement extends Element, @dotnet_named_element {
|
||||
|
||||
/** Holds if this element has the qualified name `qualifier`.`name`. */
|
||||
cached
|
||||
predicate hasQualifiedName(string qualifier, string name) {
|
||||
qualifier = "" and name = this.getName()
|
||||
predicate hasQualifiedName(string namespace, string name) {
|
||||
namespace = "" and name = this.getName()
|
||||
}
|
||||
|
||||
/** Gets a unique string label for this element. */
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
*/
|
||||
|
||||
private import Declaration
|
||||
private import semmle.code.csharp.Printing
|
||||
private import semmle.code.csharp.commons.QualifiedName
|
||||
|
||||
/** A namespace. */
|
||||
class Namespace extends Declaration, @namespace {
|
||||
@@ -20,15 +20,15 @@ class Namespace extends Declaration, @namespace {
|
||||
Namespace getAChildNamespace() { result.getParentNamespace() = this }
|
||||
|
||||
/**
|
||||
* Holds if this namespace has the qualified name `qualifier`.`name`.
|
||||
* Holds if this namespace has the qualified name `namespace`.`name`.
|
||||
*
|
||||
* For example if the qualified name is `System.Collections.Generic`, then
|
||||
* `qualifier`=`System.Collections` and `name`=`Generic`.
|
||||
* `namespace`=`System.Collections` and `name`=`Generic`.
|
||||
*/
|
||||
override predicate hasQualifiedName(string qualifier, string name) {
|
||||
exists(string pqualifier, string pname |
|
||||
this.getParentNamespace().hasQualifiedName(pqualifier, pname) and
|
||||
qualifier = printQualifiedName(pqualifier, pname)
|
||||
override predicate hasQualifiedName(string namespace, string name) {
|
||||
exists(string pnamespace, string pname |
|
||||
this.getParentNamespace().hasQualifiedName(pnamespace, pname) and
|
||||
namespace = printQualifiedName(pnamespace, pname)
|
||||
) and
|
||||
name = this.getName()
|
||||
}
|
||||
@@ -50,9 +50,9 @@ class Namespace extends Declaration, @namespace {
|
||||
* Get the fully qualified name of this namespace.
|
||||
*/
|
||||
string getFullName() {
|
||||
exists(string qualifier, string name |
|
||||
this.hasQualifiedName(qualifier, name) and
|
||||
result = printQualifiedName(qualifier, name)
|
||||
exists(string namespace, string name |
|
||||
this.hasQualifiedName(namespace, name) and
|
||||
result = printQualifiedName(namespace, name)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -61,7 +61,7 @@ class Namespace extends Declaration, @namespace {
|
||||
class GlobalNamespace extends Namespace {
|
||||
GlobalNamespace() { this.getName() = "" }
|
||||
|
||||
override predicate hasQualifiedName(string qualifier, string name) {
|
||||
qualifier = "" and name = ""
|
||||
override predicate hasQualifiedName(string namespace, string name) {
|
||||
namespace = "" and name = ""
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
*/
|
||||
|
||||
import csharp
|
||||
import semmle.code.csharp.commons.QualifiedName
|
||||
|
||||
private predicate potentialOverride(Method vm, Method m) {
|
||||
vm.getDeclaringType() = m.getDeclaringType().getBaseClass+()
|
||||
@@ -36,10 +37,10 @@ predicate nonOverridingMethod(Method m, Method vm) {
|
||||
m.getName().toLowerCase() = vm.getName().toLowerCase()
|
||||
}
|
||||
|
||||
from Method m, Method vm, string qualifier, string type, string name
|
||||
from Method m, Method vm, string namespace, string type, string name
|
||||
where
|
||||
m.fromSource() and
|
||||
nonOverridingMethod(m, vm) and
|
||||
vm.hasQualifiedName(qualifier, type, name)
|
||||
vm.hasQualifiedName(namespace, type, name)
|
||||
select m, "Method '" + m.getName() + "' looks like it should override $@ but does not do so.",
|
||||
vm.getUnboundDeclaration(), printQualifiedName(qualifier, type, name)
|
||||
vm.getUnboundDeclaration(), printQualifiedName(namespace, type, name)
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
|
||||
import csharp
|
||||
|
||||
string prefix(string qualifier, string typename) {
|
||||
qualifier = "System.Web.UI.WebControls" and
|
||||
string prefix(string namespace, string typename) {
|
||||
namespace = "System.Web.UI.WebControls" and
|
||||
(
|
||||
typename = "Label" and result = "lbl"
|
||||
or
|
||||
@@ -75,7 +75,7 @@ string prefix(string qualifier, string typename) {
|
||||
typename = "CrystalReportViewer" and result = "crvr"
|
||||
)
|
||||
or
|
||||
qualifier = "System.Web.UI.HtmlControls" and
|
||||
namespace = "System.Web.UI.HtmlControls" and
|
||||
(
|
||||
typename = "TextArea" and result = "txa"
|
||||
or
|
||||
@@ -95,11 +95,11 @@ string prefix(string qualifier, string typename) {
|
||||
)
|
||||
}
|
||||
|
||||
from Field f, RefType t, string name, string prefix, string qualifier, string type
|
||||
from Field f, RefType t, string name, string prefix, string namespace, string type
|
||||
where
|
||||
f.getType() = t and
|
||||
f.getName() = name and
|
||||
t.hasQualifiedName(qualifier, type) and
|
||||
prefix = prefix(qualifier, type) and
|
||||
t.hasQualifiedName(namespace, type) and
|
||||
prefix = prefix(namespace, type) and
|
||||
not name.matches(prefix + "%")
|
||||
select f, "This field should have the prefix '" + prefix + "' to match its types."
|
||||
|
||||
@@ -10,14 +10,7 @@
|
||||
*/
|
||||
|
||||
import Documentation
|
||||
|
||||
private string getNameSplitter() { result = "(.*)\\.([^\\.]+)$" }
|
||||
|
||||
bindingset[name]
|
||||
private predicate splitExceptionName(string name, string namespace, string type) {
|
||||
namespace = name.regexpCapture(getNameSplitter(), 1) and
|
||||
type = name.regexpCapture(getNameSplitter(), 2)
|
||||
}
|
||||
import semmle.code.csharp.commons.QualifiedName
|
||||
|
||||
from SourceMethodOrConstructor m, ThrowElement throw, RefType throwType
|
||||
where
|
||||
@@ -32,7 +25,7 @@ where
|
||||
throwBaseType.hasName(exceptionName)
|
||||
or
|
||||
exists(string namespace, string type |
|
||||
splitExceptionName(exceptionName, namespace, type) and
|
||||
splitQualifiedName(exceptionName, namespace, type) and
|
||||
throwBaseType.hasQualifiedName(namespace, type)
|
||||
)
|
||||
// and comment.hasBody(offset) // Too slow
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
*/
|
||||
|
||||
import csharp
|
||||
private import semmle.code.csharp.commons.QualifiedName
|
||||
private import semmle.code.csharp.frameworks.System
|
||||
private import semmle.code.dotnet.DotNet as DotNet // added to handle VoidType as a ValueOrRefType
|
||||
|
||||
@@ -120,10 +121,10 @@ abstract private class GeneratedType extends Type, GeneratedElement {
|
||||
}
|
||||
|
||||
private string stubComment() {
|
||||
exists(string qualifier, string name |
|
||||
this.hasQualifiedName(qualifier, name) and
|
||||
exists(string namespace, string name |
|
||||
this.hasQualifiedName(namespace, name) and
|
||||
result =
|
||||
"// Generated from `" + printQualifiedName(qualifier, name) + "` in `" +
|
||||
"// Generated from `" + printQualifiedName(namespace, name) + "` in `" +
|
||||
concat(this.getALocation().toString(), "; ") + "`\n"
|
||||
)
|
||||
}
|
||||
|
||||
@@ -14,11 +14,12 @@
|
||||
import csharp
|
||||
import DataFlow
|
||||
import JsonWebTokenHandlerLib
|
||||
import semmle.code.csharp.commons.QualifiedName
|
||||
|
||||
from
|
||||
TokenValidationParametersProperty p, CallableAlwaysReturnsTrueHigherPrecision e, string qualifier,
|
||||
TokenValidationParametersProperty p, CallableAlwaysReturnsTrueHigherPrecision e, string namespace,
|
||||
string name
|
||||
where e = p.getAnAssignedValue() and p.hasQualifiedName(qualifier, name)
|
||||
where e = p.getAnAssignedValue() and p.hasQualifiedName(namespace, name)
|
||||
select e,
|
||||
"JsonWebTokenHandler security-sensitive property $@ is being delegated to this callable that always returns \"true\".",
|
||||
p, printQualifiedName(qualifier, name)
|
||||
p, printQualifiedName(namespace, name)
|
||||
|
||||
@@ -12,14 +12,15 @@
|
||||
|
||||
import csharp
|
||||
import JsonWebTokenHandlerLib
|
||||
import semmle.code.csharp.commons.QualifiedName
|
||||
|
||||
from
|
||||
FalseValueFlowsToTokenValidationParametersPropertyWriteToBypassValidation config,
|
||||
DataFlow::Node source, DataFlow::Node sink,
|
||||
TokenValidationParametersPropertySensitiveValidation pw, string qualifier, string name
|
||||
TokenValidationParametersPropertySensitiveValidation pw, string namespace, string name
|
||||
where
|
||||
config.hasFlow(source, sink) and
|
||||
sink.asExpr() = pw.getAnAssignedValue() and
|
||||
pw.hasQualifiedName(qualifier, name)
|
||||
pw.hasQualifiedName(namespace, name)
|
||||
select sink, "The security sensitive property $@ is being disabled by the following value: $@.", pw,
|
||||
printQualifiedName(qualifier, name), source, "false"
|
||||
printQualifiedName(namespace, name), source, "false"
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import csharp
|
||||
import semmle.code.csharp.commons.QualifiedName
|
||||
|
||||
from Attributable element, Attribute attribute, string qualifier, string name
|
||||
from Attributable element, Attribute attribute, string namespace, string name
|
||||
where
|
||||
attribute = element.getAnAttribute() and
|
||||
(attribute.fromSource() or element.(Assembly).getName() in ["attributes", "Assembly1"]) and
|
||||
attribute.getType().hasQualifiedName(qualifier, name)
|
||||
select element, attribute, printQualifiedName(qualifier, name)
|
||||
attribute.getType().hasQualifiedName(namespace, name)
|
||||
select element, attribute, printQualifiedName(namespace, name)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import csharp
|
||||
import cil
|
||||
import dotnet
|
||||
import semmle.code.csharp.commons.QualifiedName
|
||||
|
||||
class MetadataEntity extends DotNet::NamedElement, @metadata_entity {
|
||||
int getHandle() { metadata_handle(this, _, result) }
|
||||
@@ -11,10 +12,10 @@ class MetadataEntity extends DotNet::NamedElement, @metadata_entity {
|
||||
}
|
||||
|
||||
query predicate tooManyHandles(string s) {
|
||||
exists(MetadataEntity e, Assembly a, string qualifier, string name |
|
||||
exists(MetadataEntity e, Assembly a, string namespace, string name |
|
||||
strictcount(int handle | metadata_handle(e, a, handle)) > 1 and
|
||||
e.hasQualifiedName(qualifier, name) and
|
||||
s = printQualifiedName(qualifier, name)
|
||||
e.hasQualifiedName(namespace, name) and
|
||||
s = printQualifiedName(namespace, name)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -30,11 +31,11 @@ private class UniqueMetadataEntity extends MetadataEntity {
|
||||
}
|
||||
|
||||
query predicate tooManyMatchingHandles(string s) {
|
||||
exists(UniqueMetadataEntity e, Assembly a, int handle, string qualifier, string name |
|
||||
exists(UniqueMetadataEntity e, Assembly a, int handle, string namespace, string name |
|
||||
metadata_handle(e, a, handle) and
|
||||
strictcount(UniqueMetadataEntity e2 | metadata_handle(e2, a, handle)) > 2 and
|
||||
e.hasQualifiedName(qualifier, name) and
|
||||
s = printQualifiedName(qualifier, name)
|
||||
e.hasQualifiedName(namespace, name) and
|
||||
s = printQualifiedName(namespace, name)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
import csharp
|
||||
import semmle.code.csharp.commons.QualifiedName
|
||||
|
||||
from TrivialProperty prop, string qualifier, string name
|
||||
from TrivialProperty prop, string namespace, string type, string name
|
||||
where
|
||||
exists(string dqualifier, string dname |
|
||||
prop.getDeclaringType().hasQualifiedName(dqualifier, dname) and
|
||||
(
|
||||
dqualifier = "System.Reflection" and dname = "AssemblyName"
|
||||
or
|
||||
dqualifier = "System.Collections" and dname = "DictionaryEntry"
|
||||
or
|
||||
dqualifier = "Dataflow" and dname = "Properties"
|
||||
)
|
||||
prop.getDeclaringType().hasQualifiedName(namespace, type) and
|
||||
(
|
||||
namespace = "System.Reflection" and type = "AssemblyName"
|
||||
or
|
||||
namespace = "System.Collections" and type = "DictionaryEntry"
|
||||
or
|
||||
namespace = "Dataflow" and type = "Properties"
|
||||
) and
|
||||
prop.hasQualifiedName(qualifier, name)
|
||||
select printQualifiedName(qualifier, name)
|
||||
prop.hasQualifiedName(namespace, type, name)
|
||||
select printQualifiedName(namespace, type, name)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import semmle.code.csharp.Printing
|
||||
import semmle.code.cil.Types
|
||||
import semmle.code.csharp.commons.QualifiedName
|
||||
|
||||
from Enum e, string qualifier, string name
|
||||
from Enum e, string namespace, string name
|
||||
where
|
||||
e.hasQualifiedName(qualifier, name) and
|
||||
printQualifiedName(qualifier, name) != "Interop.Sys.LockType" // doesn't exist on osx
|
||||
select printQualifiedName(qualifier, name), e.getUnderlyingType().toStringWithTypes()
|
||||
e.hasQualifiedName(namespace, name) and
|
||||
not (namespace = "Interop.Sys" and name = "LockType") // doesn't exist on osx
|
||||
select printQualifiedName(namespace, name), e.getUnderlyingType().toStringWithTypes()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import cil
|
||||
import semmle.code.cil.Type
|
||||
import semmle.code.csharp.Printing
|
||||
import semmle.code.csharp.commons.QualifiedName
|
||||
|
||||
bindingset[kind]
|
||||
private string getKind(int kind) { if kind = 1 then result = "modreq" else result = "modopt" }
|
||||
@@ -27,12 +27,12 @@ query predicate params(string fnptr, int i, string param, string t) {
|
||||
}
|
||||
|
||||
query predicate modifiers(string fnptr, string modifier, string sKind) {
|
||||
exists(Type modType, int kind, FunctionPointerType fn, string qualifier, string name |
|
||||
exists(Type modType, int kind, FunctionPointerType fn, string namespace, string name |
|
||||
fnptr = fn.toString()
|
||||
|
|
||||
cil_custom_modifiers(fn, modType, kind) and
|
||||
modType.hasQualifiedName(qualifier, name) and
|
||||
modifier = printQualifiedName(qualifier, name) and
|
||||
modType.hasQualifiedName(namespace, name) and
|
||||
modifier = printQualifiedName(namespace, name) and
|
||||
sKind = getKind(kind)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import semmle.code.csharp.Printing
|
||||
import semmle.code.cil.Type
|
||||
import semmle.code.csharp.commons.QualifiedName
|
||||
|
||||
bindingset[kind]
|
||||
private string getKind(int kind) { if kind = 1 then result = "modreq" else result = "modopt" }
|
||||
|
||||
from string receiver, string modifier, int kind
|
||||
where
|
||||
exists(Type modType, CustomModifierReceiver cmr, string qualifier, string name |
|
||||
exists(Type modType, CustomModifierReceiver cmr, string namespace, string name |
|
||||
receiver = cmr.toString() and
|
||||
cil_custom_modifiers(cmr, modType, kind) and
|
||||
modType.hasQualifiedName(qualifier, name) and
|
||||
modifier = printQualifiedName(qualifier, name)
|
||||
modType.hasQualifiedName(namespace, name) and
|
||||
modifier = printQualifiedName(namespace, name)
|
||||
)
|
||||
select receiver, modifier, getKind(kind)
|
||||
|
||||
@@ -3,12 +3,13 @@
|
||||
*/
|
||||
|
||||
import csharp
|
||||
import semmle.code.csharp.commons.QualifiedName
|
||||
|
||||
from EnumConstant c, string qualifier, string name
|
||||
from EnumConstant c, string namespace, string name
|
||||
where
|
||||
c.getName() = "Green" and
|
||||
c.getDeclaringType().hasQualifiedName("Enums", "LongColor") and
|
||||
c.getType() = c.getDeclaringType() and
|
||||
c.getValue() = "1" and
|
||||
c.getDeclaringType().getBaseClass().hasQualifiedName(qualifier, name)
|
||||
select c, printQualifiedName(qualifier, name)
|
||||
c.getDeclaringType().getBaseClass().hasQualifiedName(namespace, name)
|
||||
select c, printQualifiedName(namespace, name)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import csharp
|
||||
import semmle.code.csharp.commons.QualifiedName
|
||||
|
||||
query predicate test1(UnboundGenericDelegateType d) {
|
||||
d.hasName("GenericDelegate<>") and
|
||||
@@ -259,24 +260,24 @@ query predicate test32(ConstructedGeneric cg, string s1, string s2) {
|
||||
|
||||
query predicate test33(ConstructedMethod cm, string s1, string s2) {
|
||||
cm.fromSource() and
|
||||
exists(string qualifier, string type, string name |
|
||||
cm.hasQualifiedName(qualifier, type, name) and s1 = printQualifiedName(qualifier, type, name)
|
||||
exists(string namespace, string type, string name |
|
||||
cm.hasQualifiedName(namespace, type, name) and s1 = printQualifiedName(namespace, type, name)
|
||||
) and
|
||||
cm.getQualifiedNameWithTypes() = s2
|
||||
}
|
||||
|
||||
query predicate test34(UnboundGeneric ug, string s1, string s2) {
|
||||
ug.fromSource() and
|
||||
exists(string qualifier, string name |
|
||||
ug.hasQualifiedName(qualifier, name) and s1 = printQualifiedName(qualifier, name)
|
||||
exists(string namespace, string name |
|
||||
ug.hasQualifiedName(namespace, name) and s1 = printQualifiedName(namespace, name)
|
||||
) and
|
||||
ug.getQualifiedNameWithTypes() = s2
|
||||
}
|
||||
|
||||
query predicate test35(UnboundGenericMethod gm, string s1, string s2) {
|
||||
gm.fromSource() and
|
||||
exists(string qualifier, string type, string name |
|
||||
gm.hasQualifiedName(qualifier, type, name) and s1 = printQualifiedName(qualifier, type, name)
|
||||
exists(string namespace, string type, string name |
|
||||
gm.hasQualifiedName(namespace, type, name) and s1 = printQualifiedName(namespace, type, name)
|
||||
) and
|
||||
gm.getQualifiedNameWithTypes() = s2
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user