C#: Replace all uses of the deprecated hasQualifiedName/1 predicate.

This commit is contained in:
Michael Nebel
2022-11-08 13:28:30 +01:00
parent 315a3a5ed3
commit c24302bec2
140 changed files with 372 additions and 313 deletions

View File

@@ -10,5 +10,5 @@
import csharp
from CatchClause catch
where catch.getCaughtExceptionType().hasQualifiedName("System.IO.IOException")
where catch.getCaughtExceptionType().hasQualifiedName("System.IO", "IOException")
select catch

View File

@@ -10,5 +10,5 @@
import csharp
from ObjectCreation new
where new.getObjectType().hasQualifiedName("System.Exception")
where new.getObjectType().hasQualifiedName("System", "Exception")
select new

View File

@@ -13,5 +13,5 @@
import csharp
from RefType type
where type.getABaseType+().hasQualifiedName("System.Collections.IEnumerator")
where type.getABaseType+().hasQualifiedName("System.Collections", "IEnumerator")
select type

View File

@@ -11,6 +11,6 @@ import csharp
from Field f, FieldRead read
where
f.hasName("VirtualAddress") and
f.getDeclaringType().hasQualifiedName("Mono.Cecil.PE.Section") and
f.getDeclaringType().hasQualifiedName("Mono.Cecil.PE", "Section") and
f = read.getTarget()
select read

View File

@@ -12,5 +12,5 @@ from MethodCall call, Method method
where
call.getTarget() = method and
method.hasName("MethodName") and
method.getDeclaringType().hasQualifiedName("Company.Class")
method.getDeclaringType().hasQualifiedName("Company", "Class")
select call

View File

@@ -17,6 +17,6 @@ where
add.hasName("Add") and
add.getDeclaringType()
.getUnboundDeclaration()
.hasQualifiedName("System.Collections.Generic.ICollection<>") and
.hasQualifiedName("System.Collections.Generic", "ICollection<>") and
call.getAnArgument() instanceof NullLiteral
select call

View File

@@ -11,6 +11,6 @@ import csharp
from Method override, Method base
where
base.hasName("ToString") and
base.getDeclaringType().hasQualifiedName("System.Object") and
base.getDeclaringType().hasQualifiedName("System", "Object") and
base.getAnOverrider() = override
select override

View File

@@ -9,5 +9,5 @@
import csharp
from ThrowStmt throw
where throw.getThrownExceptionType().getBaseClass*().hasQualifiedName("System.IO.IOException")
where throw.getThrownExceptionType().getBaseClass*().hasQualifiedName("System.IO", "IOException")
select throw

View File

@@ -19,7 +19,7 @@ private int numStmts(ForeachStmt fes) {
}
/** Holds if the type's qualified name is "System.Linq.Enumerable" */
predicate isEnumerableType(ValueOrRefType t) { t.hasQualifiedName("System.Linq.Enumerable") }
predicate isEnumerableType(ValueOrRefType t) { t.hasQualifiedName("System.Linq", "Enumerable") }
/** Holds if the type's qualified name starts with "System.Collections.Generic.IEnumerable" */
predicate isIEnumerableType(ValueOrRefType t) {

View File

@@ -75,7 +75,7 @@ class BlockStmt extends Stmt, @block_stmt {
/** Holds if this block is the container of the global statements. */
predicate isGlobalStatementContainer() {
this.getEnclosingCallable().hasQualifiedName("Program.<Main>$")
this.getEnclosingCallable().hasQualifiedName("Program", "<Main>$")
}
override Stmt stripSingletonBlocks() {

View File

@@ -825,7 +825,7 @@ class AnonymousClass extends Class {
* The `object` type, `System.Object`.
*/
class ObjectType extends Class {
ObjectType() { this.hasQualifiedName("System.Object") }
ObjectType() { this.hasQualifiedName("System", "Object") }
override string toStringWithTypes() { result = "object" }
@@ -836,7 +836,7 @@ class ObjectType extends Class {
* The `string` type, `System.String`.
*/
class StringType extends Class {
StringType() { this.hasQualifiedName("System.String") }
StringType() { this.hasQualifiedName("System", "String") }
override string toStringWithTypes() { result = "string" }

View File

@@ -8,7 +8,7 @@ class MainMethod extends Method {
(
this.hasName("Main")
or
this.hasQualifiedName("Program.<Main>$")
this.hasQualifiedName("Program", "<Main>$")
) and
this.isStatic() and
(this.getReturnType() instanceof VoidType or this.getReturnType() instanceof IntType) and

View File

@@ -768,7 +768,7 @@ module Expressions {
nc.getOuterCompletion()
.(ThrowCompletion)
.getExceptionClass()
.hasQualifiedName("System.InvalidOperationException")
.hasQualifiedName("System", "InvalidOperationException")
)
)
}

View File

@@ -51,7 +51,7 @@ private class ThrowingCall extends NonReturningCall {
this =
any(MethodCall mc |
mc.getTarget()
.hasQualifiedName("System.Runtime.ExceptionServices.ExceptionDispatchInfo", "Throw") and
.hasQualifiedName("System.Runtime.ExceptionServices", "ExceptionDispatchInfo", "Throw") and
(
mc.hasNoArguments() and
c.getExceptionClass() instanceof SystemExceptionClass
@@ -85,8 +85,8 @@ private class DirectlyExitingCallable extends ExitingCallable {
DirectlyExitingCallable() {
this =
any(Method m |
m.hasQualifiedName("System.Environment", "Exit") or
m.hasQualifiedName("System.Windows.Forms.Application", "Exit")
m.hasQualifiedName("System", "Environment", "Exit") or
m.hasQualifiedName("System.Windows.Forms", "Application", "Exit")
)
}
}

View File

@@ -13,7 +13,7 @@ private class ExprNode = ControlFlow::Nodes::ExprNode;
* Holds if `pa` is an access to the `Length` property of an array.
*/
predicate systemArrayLengthAccess(PropertyAccess pa) {
propertyOverrides(pa.getTarget(), "System.Array", "Length")
propertyOverrides(pa.getTarget(), "System", "Array", "Length")
}
/**

View File

@@ -150,9 +150,9 @@ private module Impl {
/**
* Holds if property `p` matches `property` in `baseClass` or any overrides.
*/
predicate propertyOverrides(Property p, string baseClass, string property) {
predicate propertyOverrides(Property p, string namespace, string baseClass, string property) {
exists(Property p2 |
p2.getUnboundDeclaration().getDeclaringType().hasQualifiedName(baseClass) and
p2.getUnboundDeclaration().getDeclaringType().hasQualifiedName(namespace, baseClass) and
p2.hasName(property)
|
p.overridesOrImplementsOrEquals(p2)

View File

@@ -83,10 +83,10 @@ private module Impl {
*/
predicate containerSizeAccess(ExprNode e) {
exists(Property p | p = e.getExpr().(PropertyAccess).getTarget() |
propertyOverrides(p, "System.Collections.Generic.IEnumerable<>", "Count") or
propertyOverrides(p, "System.Collections.ICollection", "Count") or
propertyOverrides(p, "System.String", "Length") or
propertyOverrides(p, "System.Array", "Length")
propertyOverrides(p, "System.Collections.Generic", "IEnumerable<>", "Count") or
propertyOverrides(p, "System.Collections", "ICollection", "Count") or
propertyOverrides(p, "System", "String", "Length") or
propertyOverrides(p, "System", "Array", "Length")
)
or
e.getExpr() instanceof CountCall

View File

@@ -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.hasQualifiedName("", "Dapper") }
}
/** A class in `Dapper`. */

View File

@@ -20,7 +20,7 @@ module DataAnnotations {
class NotMappedAttribute extends Attribute {
NotMappedAttribute() {
this.getType()
.hasQualifiedName("System.ComponentModel.DataAnnotations.Schema.NotMappedAttribute")
.hasQualifiedName("System.ComponentModel.DataAnnotations.Schema", "NotMappedAttribute")
}
}
}

View File

@@ -27,15 +27,15 @@ class FormatMethod extends Method {
or
(this.hasName("Write") or this.hasName("WriteLine")) and
(
declType.hasQualifiedName("System.Console")
declType.hasQualifiedName("System", "Console")
or
declType.hasQualifiedName("System.IO.TextWriter")
declType.hasQualifiedName("System.IO", "TextWriter")
or
declType.hasQualifiedName("System.Diagnostics.Debug") and
declType.hasQualifiedName("System.Diagnostics", "Debug") and
this.getParameter(1).getType() instanceof ArrayType
)
or
declType.hasQualifiedName("System.Diagnostics.Trace") and
declType.hasQualifiedName("System.Diagnostics", "Trace") and
(
this.hasName("TraceError") or
this.hasName("TraceInformation") or
@@ -43,14 +43,14 @@ class FormatMethod extends Method {
)
or
this.hasName("TraceInformation") and
declType.hasQualifiedName("System.Diagnostics.TraceSource")
declType.hasQualifiedName("System.Diagnostics", "TraceSource")
or
this.hasName("Print") and
declType.hasQualifiedName("System.Diagnostics.Debug")
declType.hasQualifiedName("System.Diagnostics", "Debug")
)
or
this.hasName("Assert") and
declType.hasQualifiedName("System.Diagnostics.Debug") and
declType.hasQualifiedName("System.Diagnostics", "Debug") and
this.getNumberOfParameters() = 4
)
}
@@ -65,7 +65,7 @@ class FormatMethod extends Method {
else
if
this.hasName("Assert") and
this.getDeclaringType().hasQualifiedName("System.Diagnostics.Debug")
this.getDeclaringType().hasQualifiedName("System.Diagnostics", "Debug")
then result = 2
else result = 0
}

View File

@@ -8,7 +8,7 @@ import csharp
module JsonNET {
/** The namespace `Newtonsoft.Json`. */
class JsonNETNamespace extends Namespace {
JsonNETNamespace() { this.hasQualifiedName("Newtonsoft.Json") }
JsonNETNamespace() { this.hasQualifiedName("Newtonsoft", "Json") }
}
/** A class in `Newtonsoft.Json`. */

View File

@@ -4,7 +4,7 @@ import csharp
/** The `Moq.Language` Namespace. */
class MoqLanguageNamespace extends Namespace {
MoqLanguageNamespace() { this.hasQualifiedName("Moq.Language") }
MoqLanguageNamespace() { this.hasQualifiedName("Moq", "Language") }
}
/**

View File

@@ -14,7 +14,7 @@ module NHibernate {
/** The interface `NHibernamte.ISession`. */
class ISessionInterface extends Interface {
ISessionInterface() { this.hasQualifiedName("NHibernate.ISession") }
ISessionInterface() { this.hasQualifiedName("NHibernate", "ISession") }
/** Gets a parameter that uses a mapped object. */
Parameter getAMappedObjectParameter() {

View File

@@ -34,13 +34,14 @@ class IDbCommandConstructionSqlExpr extends SqlExpr, ObjectCreation {
exists(InstanceConstructor ic | ic = this.getTarget() |
ic.getDeclaringType().getABaseType*() instanceof SystemDataIDbCommandInterface and
ic.getParameter(0).getType() instanceof StringType and
not ic.getDeclaringType()
.hasQualifiedName([
// Known sealed classes:
"System.Data.SqlClient.SqlCommand", "System.Data.Odbc.OdbcCommand",
"System.Data.OleDb.OleDbCommand", "System.Data.EntityClient.EntityCommand",
"System.Data.SQLite.SQLiteCommand"
])
not exists(Type t | t = ic.getDeclaringType() |
// Known sealed classes:
t.hasQualifiedName("System.Data.SqlClient", "SqlCommand") or
t.hasQualifiedName("System.Data.Odbc", "OdbcCommand") or
t.hasQualifiedName("System.Data.OleDb", "OleDbCommand") or
t.hasQualifiedName("System.Data.EntityClient", "EntityCommand") or
t.hasQualifiedName("System.Data.SQLite", "SQLiteCommand")
)
)
}

View File

@@ -217,7 +217,7 @@ class MicrosoftAspNetCoreMvcController extends Class {
.getType()
.getABaseType*()
// ApiControllerAttribute is derived from ControllerAttribute
.hasQualifiedName("Microsoft.AspNetCore.Mvc.ControllerAttribute")
.hasQualifiedName("Microsoft.AspNetCore.Mvc", "ControllerAttribute")
) and
not this.getABaseType*().getAnAttribute() instanceof
MicrosoftAspNetCoreMvcNonControllerAttribute
@@ -288,7 +288,7 @@ class MicrosoftAspNetCoreHttpHttpResponse extends Class {
/** An interface that is a wrapper around the collection of cookies in the response. */
class MicrosoftAspNetCoreHttpResponseCookies extends Interface {
MicrosoftAspNetCoreHttpResponseCookies() {
this.hasQualifiedName("Microsoft.AspNetCore.Http.IResponseCookies")
this.hasQualifiedName("Microsoft.AspNetCore.Http", "IResponseCookies")
}
/** Gets the `Append` method. */

View File

@@ -5,32 +5,33 @@
import csharp
/**
* Holds if the object creation `oc` is the creation of the reference type with the specified `qualifiedName`, or a class derived from
* the class with the specified `qualifiedName`.
* Holds if the object creation `oc` is the creation of the reference type with the specified `namespace` and `type`, or a class derived from
* the class with the specified `namespace` and `type`.
*/
private predicate isCreatingObject(ObjectCreation oc, string qualifiedName) {
exists(RefType t | t = oc.getType() | t.getBaseClass*().hasQualifiedName(qualifiedName))
private predicate isCreatingObject(ObjectCreation oc, string namespace, string type) {
exists(RefType t | t = oc.getType() | t.getBaseClass*().hasQualifiedName(namespace, type))
}
/**
* Holds if the method call `mc` is returning the reference type with the specified `qualifiedName`.
* Holds if the method call `mc` is returning the reference type with the specified `namespace` and `type`.
* and the target of the method call is a library method.
*/
private predicate isReturningObject(MethodCall mc, string qualifiedName) {
private predicate isReturningObject(MethodCall mc, string namespace, string type) {
mc.getTarget().fromLibrary() and
exists(RefType t | t = mc.getType() | t.hasQualifiedName(qualifiedName))
exists(RefType t | t = mc.getType() | t.hasQualifiedName(namespace, type))
}
/**
* Holds if the method call `mc` is a call on the library method target with the specified `qualifiedName` and `methodName`, and an argument at
* Holds if the method call `mc` is a call on the library method target with the specified `namespace`, `type` and `methodName`, and an argument at
* index `argumentIndex` has the specified value `argumentValue` (case-insensitive).
*/
bindingset[argumentValue]
private predicate isMethodCalledWithArg(
MethodCall mc, string qualifiedName, string methodName, int argumentIndex, string argumentValue
MethodCall mc, string namespace, string type, string methodName, int argumentIndex,
string argumentValue
) {
mc.getTarget().fromLibrary() and
mc.getTarget().hasQualifiedName(qualifiedName, methodName) and
mc.getTarget().hasQualifiedName(namespace, type, methodName) and
mc.getArgument(argumentIndex).getValue().toUpperCase() = argumentValue.toUpperCase()
}
@@ -60,13 +61,14 @@ class SymmetricAlgorithm extends Class {
* Note: not all of the class names are supported on all platforms.
*/
predicate isCreatingDES(Expr e) {
isCreatingObject(e, "System.Security.Cryptography.DES") or
isReturningObject(e, "System.Security.Cryptography.DES") or
isMethodCalledWithArg(e, "System.Security.Cryptography.SymmetricAlgorithm", "Create", 0, "DES") or
isMethodCalledWithArg(e, "System.Security.Cryptography.SymmetricAlgorithm", "Create", 0,
isCreatingObject(e, "System.Security.Cryptography", "DES") or
isReturningObject(e, "System.Security.Cryptography", "DES") or
isMethodCalledWithArg(e, "System.Security.Cryptography", "SymmetricAlgorithm", "Create", 0, "DES") or
isMethodCalledWithArg(e, "System.Security.Cryptography", "SymmetricAlgorithm", "Create", 0,
"System.Security.Cryptography.DES") or
isMethodCalledWithArg(e, "System.Security.Cryptography.CryptoConfig", "CreateFromName", 0, "DES") or
isMethodCalledWithArg(e, "System.Security.Cryptography.CryptoConfig", "CreateFromName", 0,
isMethodCalledWithArg(e, "System.Security.Cryptography", "CryptoConfig", "CreateFromName", 0,
"DES") or
isMethodCalledWithArg(e, "System.Security.Cryptography", "CryptoConfig", "CreateFromName", 0,
"System.Security.Cryptography.DES")
}
@@ -75,21 +77,22 @@ predicate isCreatingDES(Expr e) {
* Note: not all of the class names are supported on all platforms.
*/
predicate isCreatingTripleDES(Expr e) {
isCreatingObject(e, "System.Security.Cryptography.TripleDES") or
isReturningObject(e, "System.Security.Cryptography.TripleDES") or
isMethodCalledWithArg(e, "System.Security.Cryptography.SymmetricAlgorithm", "Create", 0,
isCreatingObject(e, "System.Security.Cryptography", "TripleDES") or
isReturningObject(e, "System.Security.Cryptography", "TripleDES") or
isMethodCalledWithArg(e, "System.Security.Cryptography", "SymmetricAlgorithm", "Create", 0,
"TripleDES") or
isMethodCalledWithArg(e, "System.Security.Cryptography.SymmetricAlgorithm", "Create", 0, "3DES") or
isMethodCalledWithArg(e, "System.Security.Cryptography.SymmetricAlgorithm", "Create", 0,
isMethodCalledWithArg(e, "System.Security.Cryptography", "SymmetricAlgorithm", "Create", 0, "3DES") or
isMethodCalledWithArg(e, "System.Security.Cryptography", "SymmetricAlgorithm", "Create", 0,
"Triple DES") or
isMethodCalledWithArg(e, "System.Security.Cryptography.SymmetricAlgorithm", "Create", 0,
isMethodCalledWithArg(e, "System.Security.Cryptography", "SymmetricAlgorithm", "Create", 0,
"System.Security.Cryptography.TripleDES") or
isMethodCalledWithArg(e, "System.Security.Cryptography.CryptoConfig", "CreateFromName", 0,
isMethodCalledWithArg(e, "System.Security.Cryptography", "CryptoConfig", "CreateFromName", 0,
"TripleDES") or
isMethodCalledWithArg(e, "System.Security.Cryptography.CryptoConfig", "CreateFromName", 0, "3DES") or
isMethodCalledWithArg(e, "System.Security.Cryptography.CryptoConfig", "CreateFromName", 0,
isMethodCalledWithArg(e, "System.Security.Cryptography", "CryptoConfig", "CreateFromName", 0,
"3DES") or
isMethodCalledWithArg(e, "System.Security.Cryptography", "CryptoConfig", "CreateFromName", 0,
"Triple DES") or
isMethodCalledWithArg(e, "System.Security.Cryptography.CryptoConfig", "CreateFromName", 0,
isMethodCalledWithArg(e, "System.Security.Cryptography", "CryptoConfig", "CreateFromName", 0,
"System.Security.Cryptography.TripleDES")
}
@@ -98,13 +101,14 @@ predicate isCreatingTripleDES(Expr e) {
* Note: not all of the class names are supported on all platforms.
*/
predicate isCreatingRC2(Expr e) {
isCreatingObject(e, "System.Security.Cryptography.RC2") or
isReturningObject(e, "System.Security.Cryptography.RC2") or
isMethodCalledWithArg(e, "System.Security.Cryptography.SymmetricAlgorithm", "Create", 0, "RC2") or
isMethodCalledWithArg(e, "System.Security.Cryptography.SymmetricAlgorithm", "Create", 0,
isCreatingObject(e, "System.Security.Cryptography", "RC2") or
isReturningObject(e, "System.Security.Cryptography", "RC2") or
isMethodCalledWithArg(e, "System.Security.Cryptography", "SymmetricAlgorithm", "Create", 0, "RC2") or
isMethodCalledWithArg(e, "System.Security.Cryptography", "SymmetricAlgorithm", "Create", 0,
"System.Security.Cryptography.RC2") or
isMethodCalledWithArg(e, "System.Security.Cryptography.CryptoConfig", "CreateFromName", 0, "RC2") or
isMethodCalledWithArg(e, "System.Security.Cryptography.CryptoConfig", "CreateFromName", 0,
isMethodCalledWithArg(e, "System.Security.Cryptography", "CryptoConfig", "CreateFromName", 0,
"RC2") or
isMethodCalledWithArg(e, "System.Security.Cryptography", "CryptoConfig", "CreateFromName", 0,
"System.Security.Cryptography.RC2")
}
@@ -112,26 +116,26 @@ predicate isCreatingRC2(Expr e) {
* Holds if the expression 'e' creates Rijndael symmetric algorithm.
*/
predicate isCreatingRijndael(Expr e) {
isCreatingObject(e, "System.Security.Cryptography.Rijndael") or
isReturningObject(e, "System.Security.Cryptography.Rijndael") or
isMethodCalledWithArg(e, "System.Security.Cryptography.SymmetricAlgorithm", "Create", 0,
isCreatingObject(e, "System.Security.Cryptography", "Rijndael") or
isReturningObject(e, "System.Security.Cryptography", "Rijndael") or
isMethodCalledWithArg(e, "System.Security.Cryptography", "SymmetricAlgorithm", "Create", 0,
"Rijndael") or
isMethodCalledWithArg(e, "System.Security.Cryptography.SymmetricAlgorithm", "Create", 0,
isMethodCalledWithArg(e, "System.Security.Cryptography", "SymmetricAlgorithm", "Create", 0,
"RijndaelManaged") or
isMethodCalledWithArg(e, "System.Security.Cryptography.SymmetricAlgorithm", "Create", 0,
isMethodCalledWithArg(e, "System.Security.Cryptography", "SymmetricAlgorithm", "Create", 0,
"System.Security.Cryptography.Rijndael") or
isMethodCalledWithArg(e, "System.Security.Cryptography.SymmetricAlgorithm", "Create", 0,
isMethodCalledWithArg(e, "System.Security.Cryptography", "SymmetricAlgorithm", "Create", 0,
"System.Security.Cryptography.RijndaelManaged") or
isMethodCalledWithArg(e, "System.Security.Cryptography.SymmetricAlgorithm", "Create", 0,
isMethodCalledWithArg(e, "System.Security.Cryptography", "SymmetricAlgorithm", "Create", 0,
"System.Security.Cryptography.SymmetricAlgorithm") or // this creates Rijndael
isMethodCalledWithArg(e, "System.Security.Cryptography.CryptoConfig", "CreateFromName", 0,
isMethodCalledWithArg(e, "System.Security.Cryptography", "CryptoConfig", "CreateFromName", 0,
"Rijndael") or
isMethodCalledWithArg(e, "System.Security.Cryptography.CryptoConfig", "CreateFromName", 0,
isMethodCalledWithArg(e, "System.Security.Cryptography", "CryptoConfig", "CreateFromName", 0,
"System.Security.Cryptography.Rijndael") or
isMethodCalledWithArg(e, "System.Security.Cryptography.CryptoConfig", "CreateFromName", 0,
isMethodCalledWithArg(e, "System.Security.Cryptography", "CryptoConfig", "CreateFromName", 0,
"RijndaelManaged") or
isMethodCalledWithArg(e, "System.Security.Cryptography.CryptoConfig", "CreateFromName", 0,
isMethodCalledWithArg(e, "System.Security.Cryptography", "CryptoConfig", "CreateFromName", 0,
"System.Security.Cryptography.RijndaelManaged") or
isMethodCalledWithArg(e, "System.Security.Cryptography.CryptoConfig", "CreateFromName", 0,
isMethodCalledWithArg(e, "System.Security.Cryptography", "CryptoConfig", "CreateFromName", 0,
"System.Security.Cryptography.SymmetricAlgorithm") // this creates Rijndael
}

View File

@@ -36,7 +36,7 @@ class SystemTextRegularExpressionsRegexClass extends SystemTextRegularExpression
*/
class RegexGlobalTimeout extends MethodCall {
RegexGlobalTimeout() {
this.getTarget().hasQualifiedName("System.AppDomain.SetData") and
this.getTarget().hasQualifiedName("System.AppDomain", "SetData") and
this.getArgumentForName("name").getValue() = "REGEX_DEFAULT_MATCH_TIMEOUT"
}
}

View File

@@ -14,6 +14,19 @@ 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() {
@@ -38,7 +51,11 @@ class NUnitTestMethod extends TestMethod {
expected.getTarget() = this
|
if expected.getArgument(0).getType() instanceof StringType
then result.hasQualifiedName(expected.getArgument(0).getValue())
then
exists(string namespace, string type |
result.hasQualifiedName(namespace, type) and
splitExceptionName(expected.getArgument(0).getValue(), namespace, type)
)
else result = expected.getArgument(0).(TypeofExpr).getTypeAccess().getTarget()
)
}
@@ -56,11 +73,13 @@ class NUnitFile extends TestFile {
/** An attribute of type `NUnit.Framework.ValueSourceAttribute`. */
class ValueSourceAttribute extends Attribute {
ValueSourceAttribute() { this.getType().hasQualifiedName("NUnit.Framework.ValueSourceAttribute") }
ValueSourceAttribute() {
this.getType().hasQualifiedName("NUnit.Framework", "ValueSourceAttribute")
}
/** Holds if the first argument is the target type. */
private predicate typeSpecified() {
this.getArgument(0).getType().(Class).hasQualifiedName("System.Type") and
this.getArgument(0).getType().(Class).hasQualifiedName("System", "Type") and
this.getArgument(1).getType() instanceof StringType
}
@@ -88,12 +107,12 @@ class ValueSourceAttribute extends Attribute {
/** An attribute of type `NUnit.Framework.TestCaseSourceAttribute`. */
class TestCaseSourceAttribute extends Attribute {
TestCaseSourceAttribute() {
this.getType().hasQualifiedName("NUnit.Framework.TestCaseSourceAttribute")
this.getType().hasQualifiedName("NUnit.Framework", "TestCaseSourceAttribute")
}
/** Holds if the first argument is the target type. */
private predicate typeSpecified() {
this.getArgument(0).getType().(Class).hasQualifiedName("System.Type") and
this.getArgument(0).getType().(Class).hasQualifiedName("System", "Type") and
this.getArgument(1).getType() instanceof StringType
}
@@ -120,7 +139,7 @@ class TestCaseSourceAttribute extends Attribute {
/** The `NUnit.Framework.Assert` class. */
class NUnitAssertClass extends Class {
NUnitAssertClass() { this.hasQualifiedName("NUnit.Framework.Assert") }
NUnitAssertClass() { this.hasQualifiedName("NUnit.Framework", "Assert") }
/** Gets a `Null(object, ...)` method. */
Method getANullMethod() {
@@ -179,5 +198,5 @@ class NUnitAssertClass extends Class {
/** The `NUnit.Framework.AssertionException` class. */
class AssertionExceptionClass extends Class {
AssertionExceptionClass() { this.hasQualifiedName("NUnit.Framework.AssertionException") }
AssertionExceptionClass() { this.hasQualifiedName("NUnit.Framework", "AssertionException") }
}

View File

@@ -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.hasQualifiedName("Microsoft.VisualStudio.TestTools", "UnitTesting") }
}
/** A class that contains test methods. */

View File

@@ -5,7 +5,7 @@ import semmle.code.csharp.frameworks.Test
/** The `Xunit` namespace. */
class XUnitNamespace extends Namespace {
XUnitNamespace() { this.hasQualifiedName("Xunit") }
XUnitNamespace() { this.hasQualifiedName("", "Xunit") }
}
/** An xUnit test attribute. */

View File

@@ -162,7 +162,7 @@ class TaintToObjectTypeTrackingConfig extends TaintTracking2::Configuration {
override predicate isAdditionalTaintStep(DataFlow::Node n1, DataFlow::Node n2) {
exists(MethodCall mc, Method m |
m = mc.getTarget() and
m.getDeclaringType().hasQualifiedName("System.Type") and
m.getDeclaringType().hasQualifiedName("System", "Type") and
m.hasName("GetType") and
m.isStatic() and
n1.asExpr() = mc.getArgument(0) and

View File

@@ -46,7 +46,7 @@ class TaintTrackingConfiguration extends TaintTracking::Configuration {
class ArchiveFullNameSource extends Source {
ArchiveFullNameSource() {
exists(PropertyAccess pa | this.asExpr() = pa |
pa.getTarget().getDeclaringType().hasQualifiedName("System.IO.Compression.ZipArchiveEntry") and
pa.getTarget().getDeclaringType().hasQualifiedName("System.IO.Compression", "ZipArchiveEntry") and
pa.getTarget().getName() = "FullName"
)
}
@@ -56,7 +56,7 @@ class ArchiveFullNameSource extends Source {
class ExtractToFileArgSink extends Sink {
ExtractToFileArgSink() {
exists(MethodCall mc |
mc.getTarget().hasQualifiedName("System.IO.Compression.ZipFileExtensions", "ExtractToFile") and
mc.getTarget().hasQualifiedName("System.IO.Compression", "ZipFileExtensions", "ExtractToFile") and
this.asExpr() = mc.getArgumentForName("destinationFileName")
)
}
@@ -66,9 +66,9 @@ class ExtractToFileArgSink extends Sink {
class FileOpenArgSink extends Sink {
FileOpenArgSink() {
exists(MethodCall mc |
mc.getTarget().hasQualifiedName("System.IO.File", "Open") or
mc.getTarget().hasQualifiedName("System.IO.File", "OpenWrite") or
mc.getTarget().hasQualifiedName("System.IO.File", "Create")
mc.getTarget().hasQualifiedName("System.IO", "File", "Open") or
mc.getTarget().hasQualifiedName("System.IO", "File", "OpenWrite") or
mc.getTarget().hasQualifiedName("System.IO", "File", "Create")
|
this.asExpr() = mc.getArgumentForName("path")
)
@@ -79,7 +79,7 @@ class FileOpenArgSink extends Sink {
class FileStreamArgSink extends Sink {
FileStreamArgSink() {
exists(ObjectCreation oc |
oc.getTarget().getDeclaringType().hasQualifiedName("System.IO.FileStream")
oc.getTarget().getDeclaringType().hasQualifiedName("System.IO", "FileStream")
|
this.asExpr() = oc.getArgumentForName("path")
)
@@ -94,7 +94,7 @@ class FileStreamArgSink extends Sink {
class FileInfoArgSink extends Sink {
FileInfoArgSink() {
exists(ObjectCreation oc |
oc.getTarget().getDeclaringType().hasQualifiedName("System.IO.FileInfo")
oc.getTarget().getDeclaringType().hasQualifiedName("System.IO", "FileInfo")
|
this.asExpr() = oc.getArgumentForName("fileName")
)
@@ -108,7 +108,7 @@ class FileInfoArgSink extends Sink {
*/
class GetFileNameSanitizer extends Sanitizer {
GetFileNameSanitizer() {
exists(MethodCall mc | mc.getTarget().hasQualifiedName("System.IO.Path", "GetFileName") |
exists(MethodCall mc | mc.getTarget().hasQualifiedName("System.IO", "Path", "GetFileName") |
this.asExpr() = mc
)
}
@@ -122,19 +122,19 @@ class GetFileNameSanitizer extends Sanitizer {
*/
class SubstringSanitizer extends Sanitizer {
SubstringSanitizer() {
exists(MethodCall mc | mc.getTarget().hasQualifiedName("System.String", "Substring") |
exists(MethodCall mc | mc.getTarget().hasQualifiedName("System", "String", "Substring") |
this.asExpr() = mc
)
}
}
private predicate stringCheckGuard(Guard g, Expr e, AbstractValue v) {
g.(MethodCall).getTarget().hasQualifiedName("System.String", "StartsWith") and
g.(MethodCall).getTarget().hasQualifiedName("System", "String", "StartsWith") and
g.(MethodCall).getQualifier() = e and
// A StartsWith check against Path.Combine is not sufficient, because the ".." elements have
// not yet been resolved.
not exists(MethodCall combineCall |
combineCall.getTarget().hasQualifiedName("System.IO.Path", "Combine") and
combineCall.getTarget().hasQualifiedName("System.IO", "Path", "Combine") and
DataFlow::localExprFlow(combineCall, e)
) and
v.(AbstractValues::BooleanValue).getValue() = true

View File

@@ -47,7 +47,7 @@ abstract class InsecureXmlProcessing extends Call {
*/
private predicate isSafeXmlResolver(Expr e) {
e instanceof NullLiteral or
e.getType().(RefType).hasQualifiedName("System.Xml.XmlSecureResolver")
e.getType().(RefType).hasQualifiedName("System.Xml", "XmlSecureResolver")
}
/**
@@ -145,14 +145,16 @@ module XmlReader {
private import semmle.code.csharp.dataflow.DataFlow2
private class InsecureXmlReaderCreate extends InsecureXmlProcessing, MethodCall {
InsecureXmlReaderCreate() { this.getTarget().hasQualifiedName("System.Xml.XmlReader.Create") }
InsecureXmlReaderCreate() {
this.getTarget().hasQualifiedName("System.Xml.XmlReader", "Create")
}
/**
* Gets the `XmlReaderSettings` argument to to this call, if any.
*/
Expr getSettings() {
result = this.getAnArgument() and
result.getType().(RefType).getABaseType*().hasQualifiedName("System.Xml.XmlReaderSettings")
result.getType().(RefType).getABaseType*().hasQualifiedName("System.Xml", "XmlReaderSettings")
}
override predicate isUnsafe(string reason) {
@@ -197,7 +199,7 @@ module XmlReader {
.getType()
.(RefType)
.getABaseType*()
.hasQualifiedName("System.Xml.XmlReaderSettings")
.hasQualifiedName("System.Xml", "XmlReaderSettings")
}
override predicate isSink(DataFlow::Node sink) {
@@ -209,7 +211,7 @@ module XmlReader {
/** Provides predicates related to `System.Xml.XmlTextReader`. */
module XmlTextReader {
private class InsecureXmlTextReader extends InsecureXmlProcessing, ObjectCreation {
InsecureXmlTextReader() { this.getObjectType().hasQualifiedName("System.Xml.XmlTextReader") }
InsecureXmlTextReader() { this.getObjectType().hasQualifiedName("System.Xml", "XmlTextReader") }
override predicate isUnsafe(string reason) {
not exists(Expr xmlResolverVal |
@@ -244,8 +246,8 @@ module XmlDocument {
*/
class InsecureXmlDocument extends InsecureXmlProcessing, MethodCall {
InsecureXmlDocument() {
this.getTarget().hasQualifiedName("System.Xml.XmlDocument.Load") or
this.getTarget().hasQualifiedName("System.Xml.XmlDocument.LoadXml")
this.getTarget().hasQualifiedName("System.Xml", "XmlDocument", "Load") or
this.getTarget().hasQualifiedName("System.Xml", "XmlDocument", "LoadXml")
}
override predicate isUnsafe(string reason) {

View File

@@ -90,7 +90,7 @@ private class WrapperDeserializer extends UnsafeDeserializer {
/** BinaryFormatter */
private class BinaryFormatterClass extends Class {
BinaryFormatterClass() {
this.hasQualifiedName("System.Runtime.Serialization.Formatters.Binary.BinaryFormatter")
this.hasQualifiedName("System.Runtime.Serialization.Formatters.Binary", "BinaryFormatter")
}
}
@@ -121,7 +121,7 @@ class BinaryFormatterUnsafeDeserializeMethodResponseMethod extends Method, Unsaf
/** SoapFormatter */
private class SoapFormatterClass extends Class {
SoapFormatterClass() {
this.hasQualifiedName("System.Runtime.Serialization.Formatters.Soap.SoapFormatter")
this.hasQualifiedName("System.Runtime.Serialization.Formatters.Soap", "SoapFormatter")
}
}
@@ -135,7 +135,7 @@ class SoapFormatterDeserializeMethod extends Method, UnsafeDeserializer {
/** ObjectStateFormatter */
private class ObjectStateFormatterClass extends Class {
ObjectStateFormatterClass() { this.hasQualifiedName("System.Web.UI.ObjectStateFormatter") }
ObjectStateFormatterClass() { this.hasQualifiedName("System.Web.UI", "ObjectStateFormatter") }
}
/** `System.Web.UI.ObjectStateFormatter.Deserialize` method */
@@ -149,7 +149,7 @@ class ObjectStateFormatterDeserializeMethod extends Method, UnsafeDeserializer {
/** NetDataContractSerializer */
class NetDataContractSerializerClass extends Class {
NetDataContractSerializerClass() {
this.hasQualifiedName("System.Runtime.Serialization.NetDataContractSerializer")
this.hasQualifiedName("System.Runtime.Serialization", "NetDataContractSerializer")
}
}
@@ -172,7 +172,7 @@ class NetDataContractSerializerReadObjectMethod extends Method, UnsafeDeserializ
/** DataContractJsonSerializer */
class DataContractJsonSerializerClass extends Class {
DataContractJsonSerializerClass() {
this.hasQualifiedName("System.Runtime.Serialization.Json.DataContractJsonSerializer")
this.hasQualifiedName("System.Runtime.Serialization.Json", "DataContractJsonSerializer")
}
}
@@ -187,7 +187,7 @@ class DataContractJsonSerializerReadObjectMethod extends Method, UnsafeDeseriali
/** JavaScriptSerializer */
class JavaScriptSerializerClass extends Class {
JavaScriptSerializerClass() {
this.hasQualifiedName("System.Web.Script.Serialization.JavaScriptSerializer")
this.hasQualifiedName("System.Web.Script.Serialization", "JavaScriptSerializer")
}
}
@@ -210,7 +210,7 @@ class JavaScriptSerializerClassDeserializeObjectMethod extends Method, UnsafeDes
/** XmlObjectSerializer */
class XmlObjectSerializerClass extends Class {
XmlObjectSerializerClass() {
this.hasQualifiedName("System.Runtime.Serialization.XmlObjectSerializer")
this.hasQualifiedName("System.Runtime.Serialization", "XmlObjectSerializer")
}
}
@@ -224,7 +224,7 @@ class XmlObjectSerializerReadObjectMethod extends Method, UnsafeDeserializer {
/** XmlSerializer */
class XmlSerializerClass extends Class {
XmlSerializerClass() { this.hasQualifiedName("System.Xml.Serialization.XmlSerializer") }
XmlSerializerClass() { this.hasQualifiedName("System.Xml.Serialization", "XmlSerializer") }
}
/** `System.Xml.Serialization.XmlSerializer.Deserialize` method */
@@ -238,7 +238,7 @@ class XmlSerializerDeserializeMethod extends Method, UnsafeDeserializer {
/** DataContractSerializer */
class DataContractSerializerClass extends Class {
DataContractSerializerClass() {
this.hasQualifiedName("System.Runtime.Serialization.DataContractSerializer")
this.hasQualifiedName("System.Runtime.Serialization", "DataContractSerializer")
}
}
@@ -252,7 +252,7 @@ class DataContractSerializerReadObjectMethod extends Method, UnsafeDeserializer
/** XmlMessageFormatter */
class XmlMessageFormatterClass extends Class {
XmlMessageFormatterClass() { this.hasQualifiedName("System.Messaging.XmlMessageFormatter") }
XmlMessageFormatterClass() { this.hasQualifiedName("System.Messaging", "XmlMessageFormatter") }
}
/** `System.Messaging.XmlMessageFormatter.Read` method */
@@ -265,7 +265,7 @@ class XmlMessageFormatterReadMethod extends Method, UnsafeDeserializer {
/** LosFormatter */
private class LosFormatterClass extends Class {
LosFormatterClass() { this.hasQualifiedName("System.Web.UI.LosFormatter") }
LosFormatterClass() { this.hasQualifiedName("System.Web.UI", "LosFormatter") }
}
/** `System.Web.UI.LosFormatter.Deserialize` method */
@@ -278,7 +278,7 @@ class LosFormatterDeserializeMethod extends Method, UnsafeDeserializer {
/** fastJSON */
private class FastJsonClass extends Class {
FastJsonClass() { this.hasQualifiedName("fastJSON.JSON") }
FastJsonClass() { this.hasQualifiedName("fastJSON", "JSON") }
}
/** `fastJSON.JSON.ToObject` method */
@@ -292,7 +292,7 @@ class FastJsonClassToObjectMethod extends Method, UnsafeDeserializer {
/** Activity */
private class ActivityClass extends Class {
ActivityClass() { this.hasQualifiedName("System.Workflow.ComponentModel.Activity") }
ActivityClass() { this.hasQualifiedName("System.Workflow.ComponentModel", "Activity") }
}
/** `System.Workflow.ComponentModel.Activity.Load` method */
@@ -305,7 +305,7 @@ class ActivityLoadMethod extends Method, UnsafeDeserializer {
/** ResourceReader */
private class ResourceReaderClass extends Class {
ResourceReaderClass() { this.hasQualifiedName("System.Resources.ResourceReader") }
ResourceReaderClass() { this.hasQualifiedName("System.Resources", "ResourceReader") }
}
/** `System.Resources.ResourceReader` constructor */
@@ -318,7 +318,9 @@ class ResourceReaderConstructor extends Constructor, UnsafeDeserializer {
/** BinaryMessageFormatter */
private class BinaryMessageFormatterClass extends Class {
BinaryMessageFormatterClass() { this.hasQualifiedName("System.Messaging.BinaryMessageFormatter") }
BinaryMessageFormatterClass() {
this.hasQualifiedName("System.Messaging", "BinaryMessageFormatter")
}
}
/** `System.Messaging.BinaryMessageFormatter.Read` method */
@@ -331,7 +333,7 @@ class BinaryMessageFormatterReadMethod extends Method, UnsafeDeserializer {
/** XamlReader */
private class XamlReaderClass extends Class {
XamlReaderClass() { this.hasQualifiedName("System.Windows.Markup.XamlReader") }
XamlReaderClass() { this.hasQualifiedName("System.Windows.Markup", "XamlReader") }
}
/** `System.Windows.Markup.XamlReader.Parse` method */
@@ -362,7 +364,7 @@ class XamlReaderLoadAsyncMethod extends Method, UnsafeDeserializer {
/** ProxyObject */
private class ProxyObjectClass extends Class {
ProxyObjectClass() { this.hasQualifiedName("Microsoft.Web.Design.Remote.ProxyObject") }
ProxyObjectClass() { this.hasQualifiedName("Microsoft.Web.Design.Remote", "ProxyObject") }
}
/** `Microsoft.Web.Design.Remote.ProxyObject.DecodeValue` method */
@@ -383,7 +385,7 @@ class ProxyObjectDecodeSerializedObjectMethod extends Method, UnsafeDeserializer
/** SweetJayson */
private class JaysonConverterClass extends Class {
JaysonConverterClass() { this.hasQualifiedName("Sweet.Jayson.JaysonConverter") }
JaysonConverterClass() { this.hasQualifiedName("Sweet.Jayson", "JaysonConverter") }
}
/** `Sweet.Jayson.JaysonConverter.ToObject` method */
@@ -398,7 +400,7 @@ class JaysonConverterToObjectMethod extends Method, UnsafeDeserializer {
/** ServiceStack.Text.JsonSerializer */
private class ServiceStackTextJsonSerializerClass extends Class {
ServiceStackTextJsonSerializerClass() {
this.hasQualifiedName("ServiceStack.Text.JsonSerializer")
this.hasQualifiedName("ServiceStack.Text", "JsonSerializer")
}
}
@@ -432,7 +434,7 @@ class ServiceStackTextJsonSerializerDeserializeFromStreamMethod extends Method,
/** ServiceStack.Text.TypeSerializer */
private class ServiceStackTextTypeSerializerClass extends Class {
ServiceStackTextTypeSerializerClass() {
this.hasQualifiedName("ServiceStack.Text.TypeSerializer")
this.hasQualifiedName("ServiceStack.Text", "TypeSerializer")
}
}
@@ -465,7 +467,9 @@ class ServiceStackTextTypeSerializerDeserializeFromStreamMethod extends Method,
/** ServiceStack.Text.CsvSerializer */
private class ServiceStackTextCsvSerializerClass extends Class {
ServiceStackTextCsvSerializerClass() { this.hasQualifiedName("ServiceStack.Text.CsvSerializer") }
ServiceStackTextCsvSerializerClass() {
this.hasQualifiedName("ServiceStack.Text", "CsvSerializer")
}
}
/** `ServiceStack.Text.CsvSerializer.DeserializeFromString` method */
@@ -497,7 +501,9 @@ class ServiceStackTextCsvSerializerDeserializeFromStreamMethod extends Method, U
/** ServiceStack.Text.XmlSerializer */
private class ServiceStackTextXmlSerializerClass extends Class {
ServiceStackTextXmlSerializerClass() { this.hasQualifiedName("ServiceStack.Text.XmlSerializer") }
ServiceStackTextXmlSerializerClass() {
this.hasQualifiedName("ServiceStack.Text", "XmlSerializer")
}
}
/** `ServiceStack.Text.XmlSerializer.DeserializeFromString` method */
@@ -529,7 +535,7 @@ class ServiceStackTextXmlSerializerDeserializeFromStreamMethod extends Method, U
/** MBrace.FsPickler.FsPicklerSerializer */
private class FsPicklerSerializerClass extends Class {
FsPicklerSerializerClass() { this.hasQualifiedName("MBrace.FsPickler.FsPicklerSerializer") }
FsPicklerSerializerClass() { this.hasQualifiedName("MBrace.FsPickler", "FsPicklerSerializer") }
}
/** `MBrace.FsPickler.FsPicklerSerializer.Deserialize` method */
@@ -598,7 +604,7 @@ class FsPicklerSerializerClassUnPickleUntypedMethod extends Method, UnsafeDeseri
/** MBrace.CsPickler.CsPicklerSerializer */
private class CsPicklerSerializerClass extends Class {
CsPicklerSerializerClass() { this.hasQualifiedName("MBrace.CsPickler.CsPicklerSerializer") }
CsPicklerSerializerClass() { this.hasQualifiedName("MBrace.CsPickler", "CsPicklerSerializer") }
}
/** `MBrace.FsPickler.CsPicklerSerializer.Deserialize` method */
@@ -620,7 +626,7 @@ class CsPicklerSerializerClassUnPickleMethod extends Method, UnsafeDeserializer
/** MBrace.CsPickler.CsPicklerTextSerializer */
private class CsPicklerTextSerializerClass extends Class {
CsPicklerTextSerializerClass() {
this.hasQualifiedName("MBrace.CsPickler.CsPicklerTextSerializer")
this.hasQualifiedName("MBrace.CsPickler", "CsPicklerTextSerializer")
}
}
@@ -634,7 +640,7 @@ class CsPicklerSerializerClassUnPickleOfStringMethod extends Method, UnsafeDeser
/** Polenter.Serialization.SharpSerializer */
private class SharpSerializerClass extends Class {
SharpSerializerClass() { this.hasQualifiedName("Polenter.Serialization.SharpSerializer") }
SharpSerializerClass() { this.hasQualifiedName("Polenter.Serialization", "SharpSerializer") }
}
/** `Polenter.Serialization.SharpSerializer.Deserialize` method */
@@ -647,7 +653,9 @@ class SharpSerializerClassDeserializeMethod extends Method, UnsafeDeserializer {
/** YamlDotNet.Serialization.Deserializer */
private class YamlDotNetDeserializerClass extends Class {
YamlDotNetDeserializerClass() { this.hasQualifiedName("YamlDotNet.Serialization.Deserializer") }
YamlDotNetDeserializerClass() {
this.hasQualifiedName("YamlDotNet.Serialization", "Deserializer")
}
}
/** `YamlDotNet.Serialization.Deserializer.Deserialize` method */

View File

@@ -16,5 +16,5 @@ where
c.getTarget() = gcCollect and
gcCollect.hasName("Collect") and
gcCollect.hasNoParameters() and
gcCollect.getDeclaringType().hasQualifiedName("System.GC")
gcCollect.getDeclaringType().hasQualifiedName("System", "GC")
select c, "Call to 'GC.Collect()'."

View File

@@ -19,6 +19,6 @@ where
m.fromSource() and
exists(UsingNamespaceDirective u |
u.getFile() = m.getFile() and
u.getImportedNamespace().hasQualifiedName("System.Web")
u.getImportedNamespace().hasQualifiedName("System", "Web")
)
select m, "Remove debug code if your ASP.NET application is in production."

View File

@@ -29,7 +29,7 @@ predicate usedInHumanWrittenCode(Field f) {
from Field field, ValueOrRefType widget, string prefix
where
widget.getABaseType*().hasQualifiedName("System.Windows.Forms.Control") and
widget.getABaseType*().hasQualifiedName("System.Windows.Forms", "Control") and
field.getType() = widget and
field.getName().regexpMatch(prefix + "[0-9]+") and
controlName(prefix) and

View File

@@ -14,30 +14,30 @@ import semmle.code.csharp.commons.Util
predicate isConsoleOutRedefinedSomewhere() {
exists(MethodCall mc |
mc.getTarget().hasName("SetOut") and
mc.getTarget().getDeclaringType().hasQualifiedName("System.Console")
mc.getTarget().getDeclaringType().hasQualifiedName("System", "Console")
)
}
predicate isConsoleErrorRedefinedSomewhere() {
exists(MethodCall mc |
mc.getTarget().hasName("SetError") and
mc.getTarget().getDeclaringType().hasQualifiedName("System.Console")
mc.getTarget().getDeclaringType().hasQualifiedName("System", "Console")
)
}
predicate isCallToConsoleWrite(MethodCall mc) {
mc.getTarget().getName().matches("Write%") and
mc.getTarget().getDeclaringType().hasQualifiedName("System.Console")
mc.getTarget().getDeclaringType().hasQualifiedName("System", "Console")
}
predicate isAccessToConsoleOut(PropertyAccess pa) {
pa.getTarget().hasName("Out") and
pa.getTarget().getDeclaringType().hasQualifiedName("System.Console")
pa.getTarget().getDeclaringType().hasQualifiedName("System", "Console")
}
predicate isAccessToConsoleError(PropertyAccess pa) {
pa.getTarget().hasName("Error") and
pa.getTarget().getDeclaringType().hasQualifiedName("System.Console")
pa.getTarget().getDeclaringType().hasQualifiedName("System", "Console")
}
from Expr e

View File

@@ -5,7 +5,7 @@ import csharp
private class WaitCall extends MethodCall {
WaitCall() {
this.getTarget().hasName("Wait") and
this.getTarget().getDeclaringType().hasQualifiedName("System.Threading.Monitor")
this.getTarget().getDeclaringType().hasQualifiedName("System.Threading", "Monitor")
}
Expr getExpr() { result = this.getArgument(0) }
@@ -30,12 +30,12 @@ class WaitStmt extends ExprStmt {
private class SynchronizedMethodAttribute extends Attribute {
SynchronizedMethodAttribute() {
this.getType().hasQualifiedName("System.Runtime.CompilerServices.MethodImplAttribute") and
this.getType().hasQualifiedName("System.Runtime.CompilerServices", "MethodImplAttribute") and
exists(MemberConstantAccess a, MemberConstant mc |
a = this.getArgument(0) and
a.getTarget() = mc and
mc.hasName("Synchronized") and
mc.getDeclaringType().hasQualifiedName("System.Runtime.CompilerServices.MethodImplOptions")
mc.getDeclaringType().hasQualifiedName("System.Runtime.CompilerServices", "MethodImplOptions")
)
}
}

View File

@@ -26,7 +26,7 @@ Expr getAnAccessByDynamicCall(Method m) {
exists(MethodCall mc, Method target |
target = mc.getTarget() and
target.hasName("InvokeMember") and
target.getDeclaringType().hasQualifiedName("System.Type") and
target.getDeclaringType().hasQualifiedName("System", "Type") and
mc.getArgument(0).(StringLiteral).getValue() = m.getName() and
mc.getArgument(3).getType().(RefType).hasMethod(m) and
result = mc
@@ -42,7 +42,7 @@ Expr getAMethodAccess(Method m) {
predicate potentiallyAccessedByForEach(Method m) {
m.hasName("GetEnumerator") and
m.getDeclaringType().getABaseType+().hasQualifiedName("System.Collections.IEnumerable")
m.getDeclaringType().getABaseType+().hasQualifiedName("System.Collections", "IEnumerable")
or
foreach_stmt_desugar(_, m, 1)
}

View File

@@ -24,7 +24,7 @@ predicate potentiallyUsedFromXaml(RefType t) {
class ExportAttribute extends Attribute {
ExportAttribute() {
getType().hasQualifiedName("System.ComponentModel.Composition.ExportAttribute")
getType().hasQualifiedName("System.ComponentModel.Composition", "ExportAttribute")
}
}

View File

@@ -11,6 +11,14 @@
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)
}
from SourceMethodOrConstructor m, ThrowElement throw, RefType throwType
where
declarationHasXmlComment(m) and
@@ -20,8 +28,15 @@ where
comment = getADeclarationXmlComment(m) and
exceptionName = comment.getCref(offset) and
throwType.getABaseType*() = throwBaseType and
(throwBaseType.hasName(exceptionName) or throwBaseType.hasQualifiedName(exceptionName))
// and comment.hasBody(offset) // Too slow
(
throwBaseType.hasName(exceptionName)
or
exists(string namespace, string type |
splitExceptionName(exceptionName, namespace, type) and
throwBaseType.hasQualifiedName(namespace, type)
)
// and comment.hasBody(offset) // Too slow
)
) and
not getADeclarationXmlComment(m) instanceof InheritDocXmlComment
select m, "Exception $@ should be documented.", throw, throw.getExpr().getType().getName()

View File

@@ -13,9 +13,9 @@
import csharp
import semmle.code.csharp.commons.Assertions
private predicate propertyOverrides(Property p, string baseClass, string property) {
private predicate propertyOverrides(Property p, string namespace, string baseClass, string property) {
exists(Property p2 |
p2.getUnboundDeclaration().getDeclaringType().hasQualifiedName(baseClass) and
p2.getUnboundDeclaration().getDeclaringType().hasQualifiedName(namespace, baseClass) and
p2.hasName(property)
|
p.overridesOrImplementsOrEquals(p2)
@@ -24,16 +24,16 @@ private predicate propertyOverrides(Property p, string baseClass, string propert
private predicate containerSizeAccess(PropertyAccess pa, string containerKind) {
(
propertyOverrides(pa.getTarget(), "System.Collections.Generic.ICollection<>", "Count") or
propertyOverrides(pa.getTarget(), "System.Collections.Generic.IReadOnlyCollection<>", "Count") or
propertyOverrides(pa.getTarget(), "System.Collections.ICollection", "Count")
propertyOverrides(pa.getTarget(), "System.Collections.Generic", "ICollection<>", "Count") or
propertyOverrides(pa.getTarget(), "System.Collections.Generic", "IReadOnlyCollection<>", "Count") or
propertyOverrides(pa.getTarget(), "System.Collections", "ICollection", "Count")
) and
containerKind = "a collection"
or
(
propertyOverrides(pa.getTarget(), "System.String", "Length") and containerKind = "a string"
propertyOverrides(pa.getTarget(), "System", "String", "Length") and containerKind = "a string"
or
propertyOverrides(pa.getTarget(), "System.Array", "Length") and containerKind = "an array"
propertyOverrides(pa.getTarget(), "System", "Array", "Length") and containerKind = "an array"
)
}

View File

@@ -20,14 +20,14 @@ class UnsafeYearCreationFromArithmeticConfiguration extends TaintTracking::Confi
override predicate isSource(DataFlow::Node source) {
exists(ArithmeticOperation ao, PropertyAccess pa | ao = source.asExpr() |
pa = ao.getAChild*() and
pa.getProperty().hasQualifiedName("System.DateTime.Year")
pa.getProperty().hasQualifiedName("System.DateTime", "Year")
)
}
override predicate isSink(DataFlow::Node sink) {
exists(ObjectCreation oc |
sink.asExpr() = oc.getArgumentForName("year") and
oc.getObjectType().getABaseType*().hasQualifiedName("System.DateTime")
oc.getObjectType().getABaseType*().hasQualifiedName("System", "DateTime")
)
}
}

View File

@@ -23,8 +23,8 @@ predicate isEraStart(int year, int month, int day) {
predicate isExactEraStartDateCreation(ObjectCreation cr) {
(
cr.getType().hasQualifiedName("System.DateTime") or
cr.getType().hasQualifiedName("System.DateTimeOffset")
cr.getType().hasQualifiedName("System", "DateTime") or
cr.getType().hasQualifiedName("System", "DateTimeOffset")
) and
isEraStart(cr.getArgument(0).getValue().toInt(), cr.getArgument(1).getValue().toInt(),
cr.getArgument(2).getValue().toInt())
@@ -32,8 +32,10 @@ predicate isExactEraStartDateCreation(ObjectCreation cr) {
predicate isDateFromJapaneseCalendarToDateTime(MethodCall mc) {
(
mc.getQualifier().getType().hasQualifiedName("System.Globalization.JapaneseCalendar") or
mc.getQualifier().getType().hasQualifiedName("System.Globalization.JapaneseLunisolarCalendar")
mc.getQualifier().getType().hasQualifiedName("System.Globalization", "JapaneseCalendar") or
mc.getQualifier()
.getType()
.hasQualifiedName("System.Globalization", "JapaneseLunisolarCalendar")
) and
mc.getTarget().hasName("ToDateTime") and
mc.getArgument(0).hasValue() and
@@ -47,16 +49,16 @@ predicate isDateFromJapaneseCalendarToDateTime(MethodCall mc) {
predicate isDateFromJapaneseCalendarCreation(ObjectCreation cr) {
(
cr.getType().hasQualifiedName("System.DateTime") or
cr.getType().hasQualifiedName("System.DateTimeOffset")
cr.getType().hasQualifiedName("System", "DateTime") or
cr.getType().hasQualifiedName("System", "DateTimeOffset")
) and
(
cr.getArgumentForName("calendar")
.getType()
.hasQualifiedName("System.Globalization.JapaneseCalendar") or
.hasQualifiedName("System.Globalization", "JapaneseCalendar") or
cr.getArgumentForName("calendar")
.getType()
.hasQualifiedName("System.Globalization.JapaneseLunisolarCalendar")
.hasQualifiedName("System.Globalization", "JapaneseLunisolarCalendar")
) and
cr.getArgumentForName("year").hasValue()
}

View File

@@ -27,7 +27,7 @@ class TaintTrackingConfiguration extends TaintTracking::Configuration {
override predicate isSink(DataFlow::Node sink) {
exists(MethodCall mc |
mc.getTarget().hasName("WriteRaw") and
mc.getTarget().getDeclaringType().getABaseType*().hasQualifiedName("System.Xml.XmlWriter")
mc.getTarget().getDeclaringType().getABaseType*().hasQualifiedName("System.Xml", "XmlWriter")
|
mc.getArgument(0) = sink.asExpr()
)
@@ -39,7 +39,7 @@ class TaintTrackingConfiguration extends TaintTracking::Configuration {
mc.getTarget()
.getDeclaringType()
.getABaseType*()
.hasQualifiedName("System.Security.SecurityElement")
.hasQualifiedName("System.Security", "SecurityElement")
|
mc = node.asExpr()
)

View File

@@ -34,7 +34,7 @@ class TaintTrackingConfiguration extends TaintTracking::Configuration {
mc.getTarget()
.getDeclaringType()
.getABaseType*()
.hasQualifiedName("System.Reflection.Assembly") and
.hasQualifiedName("System.Reflection", "Assembly") and
mc.getArgument(arg) = sink.asExpr()
|
name = "LoadFrom" and arg = 0 and mc.getNumberOfArguments() = [1 .. 2]

View File

@@ -21,7 +21,7 @@ class AddCertToRootStoreConfig extends DataFlow::Configuration {
exists(ObjectCreation oc | oc = source.asExpr() |
oc.getType()
.(RefType)
.hasQualifiedName("System.Security.Cryptography.X509Certificates.X509Store") and
.hasQualifiedName("System.Security.Cryptography.X509Certificates", "X509Store") and
oc.getArgument(0).(Access).getTarget().hasName("Root")
)
}
@@ -30,9 +30,10 @@ class AddCertToRootStoreConfig extends DataFlow::Configuration {
exists(MethodCall mc |
(
mc.getTarget()
.hasQualifiedName("System.Security.Cryptography.X509Certificates.X509Store", "Add") or
.hasQualifiedName("System.Security.Cryptography.X509Certificates", "X509Store", "Add") or
mc.getTarget()
.hasQualifiedName("System.Security.Cryptography.X509Certificates.X509Store", "AddRange")
.hasQualifiedName("System.Security.Cryptography.X509Certificates", "X509Store",
"AddRange")
) and
sink.asExpr() = mc.getQualifier()
)

View File

@@ -30,7 +30,7 @@ predicate loginMethod(Method m, ControlFlow::SuccessorType flowFrom) {
/** The `System.Web.SessionState.HttpSessionState` class. */
class SystemWebSessionStateHttpSessionStateClass extends Class {
SystemWebSessionStateHttpSessionStateClass() {
this.hasQualifiedName("System.Web.SessionState.HttpSessionState")
this.hasQualifiedName("System.Web.SessionState", "HttpSessionState")
}
/** Gets the `Abandon` method. */

View File

@@ -68,7 +68,7 @@ module RequestForgery {
*/
private class SystemWebHttpRequestMessageSink extends Sink {
SystemWebHttpRequestMessageSink() {
exists(Class c | c.hasQualifiedName("System.Net.Http.HttpRequestMessage") |
exists(Class c | c.hasQualifiedName("System.Net.Http", "HttpRequestMessage") |
c.getAConstructor().getACall().getArgument(1) = this.asExpr()
)
}
@@ -81,7 +81,7 @@ module RequestForgery {
private class SystemNetWebRequestCreateSink extends Sink {
SystemNetWebRequestCreateSink() {
exists(Method m |
m.getDeclaringType().hasQualifiedName("System.Net.WebRequest") and m.hasName("Create")
m.getDeclaringType().hasQualifiedName("System.Net", "WebRequest") and m.hasName("Create")
|
m.getACall().getArgument(0) = this.asExpr()
)
@@ -95,7 +95,7 @@ module RequestForgery {
private class SystemNetHttpClientSink extends Sink {
SystemNetHttpClientSink() {
exists(Method m |
m.getDeclaringType().hasQualifiedName("System.Net.Http.HttpClient") and
m.getDeclaringType().hasQualifiedName("System.Net.Http", "HttpClient") and
m.hasName([
"DeleteAsync", "GetAsync", "GetByteArrayAsync", "GetStreamAsync", "GetStringAsync",
"PatchAsync", "PostAsync", "PutAsync"
@@ -112,10 +112,13 @@ module RequestForgery {
*/
private class SystemNetClientBaseAddressSink extends Sink {
SystemNetClientBaseAddressSink() {
exists(Property p |
exists(Property p, Type t |
p.hasName("BaseAddress") and
p.getDeclaringType()
.hasQualifiedName(["System.Net.WebClient", "System.Net.Http.HttpClient"])
t = p.getDeclaringType() and
(
t.hasQualifiedName("System.Net", "WebClient") or
t.hasQualifiedName("System.Net.Http", "HttpClient")
)
|
p.getAnAssignedValue() = this.asExpr()
)
@@ -128,7 +131,7 @@ module RequestForgery {
* This guard considers all checks as valid.
*/
private predicate baseUriGuard(Guard g, Expr e, AbstractValue v) {
g.(MethodCall).getTarget().hasQualifiedName("System.Uri", "IsBaseOf") and
g.(MethodCall).getTarget().hasQualifiedName("System", "Uri", "IsBaseOf") and
// we consider any checks against the tainted value to sainitize the taint.
// This implies any check such as shown below block the taint flow.
// Uri url = new Uri("whitelist.com")
@@ -147,7 +150,7 @@ module RequestForgery {
* This guard considers all checks as valid.
*/
private predicate stringStartsWithGuard(Guard g, Expr e, AbstractValue v) {
g.(MethodCall).getTarget().hasQualifiedName("System.String", "StartsWith") and
g.(MethodCall).getTarget().hasQualifiedName("System", "String", "StartsWith") and
// Any check such as the ones shown below
// "https://myurl.com/".startsWith(`taint`)
// `taint`.startsWith("https://myurl.com/")
@@ -168,7 +171,7 @@ module RequestForgery {
private predicate pathCombineStep(DataFlow::Node prev, DataFlow::Node succ) {
exists(MethodCall combineCall |
combineCall.getTarget().hasQualifiedName("System.IO.Path", "Combine") and
combineCall.getTarget().hasQualifiedName("System.IO", "Path", "Combine") and
combineCall.getArgument(0) = prev.asExpr() and
combineCall = succ.asExpr()
)
@@ -176,7 +179,7 @@ module RequestForgery {
private predicate uriCreationStep(DataFlow::Node prev, DataFlow::Node succ) {
exists(ObjectCreation oc |
oc.getTarget().getDeclaringType().hasQualifiedName("System.Uri") and
oc.getTarget().getDeclaringType().hasQualifiedName("System", "Uri") and
oc.getArgument(0) = prev.asExpr() and
oc = succ.asExpr()
)
@@ -217,7 +220,7 @@ module RequestForgery {
private predicate formatConvertStep(DataFlow::Node prev, DataFlow::Node succ) {
exists(Method m |
m.hasQualifiedName("System.Convert",
m.hasQualifiedName("System", "Convert",
["FromBase64String", "FromHexString", "FromBase64CharArray"]) and
m.getParameter(0) = prev.asParameter() and
succ.asExpr() = m.getACall()

View File

@@ -18,7 +18,7 @@ import csharp
*/
predicate isCreatingAzureClientSideEncryptionObject(ObjectCreation oc, Class c, Expr e) {
exists(Parameter p | p.hasName("version") |
c.hasQualifiedName("Azure.Storage.ClientSideEncryptionOptions") and
c.hasQualifiedName("Azure.Storage", "ClientSideEncryptionOptions") and
oc.getTarget() = c.getAConstructor() and
e = oc.getArgumentForParameter(p)
)
@@ -28,7 +28,7 @@ predicate isCreatingAzureClientSideEncryptionObject(ObjectCreation oc, Class c,
* Holds if `oc` is an object creation of the outdated type `c` = `Microsoft.Azure.Storage.Blob.BlobEncryptionPolicy`
*/
predicate isCreatingOutdatedAzureClientSideEncryptionObject(ObjectCreation oc, Class c) {
c.hasQualifiedName("Microsoft.Azure.Storage.Blob.BlobEncryptionPolicy") and
c.hasQualifiedName("Microsoft.Azure.Storage.Blob", "BlobEncryptionPolicy") and
oc.getTarget() = c.getAConstructor()
}
@@ -62,7 +62,7 @@ predicate isObjectCreationArgumentSafeAndUsingSafeVersionOfAssembly(Expr version
*/
predicate isExprAnAccessToSafeClientSideEncryptionVersionValue(Expr e) {
exists(EnumConstant ec |
ec.hasQualifiedName("Azure.Storage.ClientSideEncryptionVersion.V2_0") and
ec.hasQualifiedName("Azure.Storage.ClientSideEncryptionVersion", "V2_0") and
ec.getAnAccess() = e
)
}

View File

@@ -96,10 +96,10 @@ predicate hasAnotherHashCall(MethodCall mc) {
predicate hasFurtherProcessing(MethodCall mc) {
mc.getTarget().fromLibrary() and
(
mc.getTarget().hasQualifiedName("System.Array", "Copy") or // Array.Copy(passwordHash, 0, password.Length), 0, key, 0, keyLen);
mc.getTarget().hasQualifiedName("System.String", "Concat") or // string.Concat(passwordHash, saltkey)
mc.getTarget().hasQualifiedName("System.Buffer", "BlockCopy") or // Buffer.BlockCopy(passwordHash, 0, allBytes, 0, 20)
mc.getTarget().hasQualifiedName("System.String", "Format") // String.Format("{0}:{1}:{2}", username, salt, password)
mc.getTarget().hasQualifiedName("System", "Array", "Copy") or // Array.Copy(passwordHash, 0, password.Length), 0, key, 0, keyLen);
mc.getTarget().hasQualifiedName("System", "String", "Concat") or // string.Concat(passwordHash, saltkey)
mc.getTarget().hasQualifiedName("System", "Buffer", "BlockCopy") or // Buffer.BlockCopy(passwordHash, 0, allBytes, 0, 20)
mc.getTarget().hasQualifiedName("System", "String", "Format") // String.Format("{0}:{1}:{2}", username, salt, password)
)
}
@@ -150,7 +150,7 @@ class HashWithoutSaltConfiguration extends TaintTracking::Configuration {
override predicate isAdditionalTaintStep(DataFlow::Node node1, DataFlow::Node node2) {
exists(MethodCall mc |
mc.getTarget()
.hasQualifiedName("Windows.Security.Cryptography.CryptographicBuffer",
.hasQualifiedName("Windows.Security.Cryptography", "CryptographicBuffer",
"ConvertStringToBinary") and
mc.getArgument(0) = node1.asExpr() and
mc = node2.asExpr()

View File

@@ -7,7 +7,7 @@ import DataFlow
class TokenValidationParametersPropertySensitiveValidation extends Property {
TokenValidationParametersPropertySensitiveValidation() {
exists(Class c |
c.hasQualifiedName("Microsoft.IdentityModel.Tokens.TokenValidationParameters")
c.hasQualifiedName("Microsoft.IdentityModel.Tokens", "TokenValidationParameters")
|
c.getAProperty() = this and
this.getName() in [
@@ -52,8 +52,10 @@ predicate isAssemblyOlderVersion(string assemblyName, string ver) {
*/
class JsonWebTokenHandlerValidateTokenMethod extends Method {
JsonWebTokenHandlerValidateTokenMethod() {
this.hasQualifiedName("Microsoft.IdentityModel.JsonWebTokens.JsonWebTokenHandler.ValidateToken") or
this.hasQualifiedName("Microsoft.AzureAD.DeviceIdentification.Common.Tokens.JwtValidator.ValidateEncryptedToken")
this.hasQualifiedName("Microsoft.IdentityModel.JsonWebTokens", "JsonWebTokenHandler",
"ValidateToken") or
this.hasQualifiedName("Microsoft.AzureAD.DeviceIdentification.Common.Tokens", "JwtValidator",
"ValidateEncryptedToken")
}
}
@@ -99,7 +101,7 @@ private class FlowsToTokenValidationResultIsValidCall extends DataFlow::Configur
class TokenValidationParametersProperty extends Property {
TokenValidationParametersProperty() {
exists(Class c |
c.hasQualifiedName("Microsoft.IdentityModel.Tokens.TokenValidationParameters")
c.hasQualifiedName("Microsoft.IdentityModel.Tokens", "TokenValidationParameters")
|
c.getAProperty() = this and
this.getName() in [
@@ -158,7 +160,7 @@ class CallableAlwaysReturnsTrue extends Callable {
*/
predicate callableOnlyThrowsArgumentNullException(Callable c) {
forall(ThrowElement thre | c = thre.getEnclosingCallable() |
thre.getThrownExceptionType().hasQualifiedName("System.ArgumentNullException")
thre.getThrownExceptionType().hasQualifiedName("System", "ArgumentNullException")
)
}

View File

@@ -14,7 +14,9 @@ import DataSetSerialization
predicate xmlSerializerConstructorArgument(Expr e) {
exists(ObjectCreation oc, Constructor c | e = oc.getArgument(0) |
c = oc.getTarget() and
c.getDeclaringType().getABaseType*().hasQualifiedName("System.Xml.Serialization.XmlSerializer")
c.getDeclaringType()
.getABaseType*()
.hasQualifiedName("System.Xml.Serialization", "XmlSerializer")
)
}

View File

@@ -20,7 +20,7 @@ from
Class class1, MissingType class2, MissingType class3, MissingType class4, MissingType class5,
MissingType del2, Field a, Method b, Method c, Method d, Method e, Method f, Method g
where
class1.hasQualifiedName("Assembly1.Class1") and
class1.hasQualifiedName("Assembly1", "Class1") and
class2.hasName("Class2") and
class3.hasName("Class3") and
class4.hasName("Class4") and

View File

@@ -2,7 +2,7 @@ import csharp
from Element e, Class c, Method m, Parameter p
where
c.hasQualifiedName("Locations.Test") and
c.hasQualifiedName("Locations", "Test") and
m.getDeclaringType() = c and
m.getAParameter() = p and
(e = c or e = m or e = p)

View File

@@ -2,9 +2,9 @@ import csharp
from TrivialProperty prop
where
prop.getDeclaringType().hasQualifiedName("System.Reflection.AssemblyName")
prop.getDeclaringType().hasQualifiedName("System.Reflection", "AssemblyName")
or
prop.getDeclaringType().hasQualifiedName("System.Collections.DictionaryEntry")
prop.getDeclaringType().hasQualifiedName("System.Collections", "DictionaryEntry")
or
prop.getDeclaringType().hasQualifiedName("Dataflow.Properties")
prop.getDeclaringType().hasQualifiedName("Dataflow", "Properties")
select prop.getQualifiedName()

View File

@@ -1,7 +1,7 @@
import csharp
query predicate fileScopedNamespace(Namespace n, Member m) {
n.hasQualifiedName("MyFileScopedNamespace") and
n.hasQualifiedName("", "MyFileScopedNamespace") and
exists(Class c |
c.getNamespace() = n and
c.hasMember(m) and

View File

@@ -14,7 +14,7 @@ class MySink extends DataFlow::ExprNode {
class MySource extends DataFlow::ParameterNode {
MySource() {
exists(Parameter p | p = this.getParameter() |
p = any(Class c | c.hasQualifiedName("Test")).getAMethod().getAParameter()
p = any(Class c | c.hasQualifiedName("", "Test")).getAMethod().getAParameter()
)
}
}

View File

@@ -6,7 +6,7 @@ import csharp
from DelegateType d
where
d.hasQualifiedName("Delegates.FooDelegate") and
d.hasQualifiedName("Delegates", "FooDelegate") and
d.getReturnType() instanceof DoubleType and
d.getParameter(0).hasName("param") and
d.getParameter(0).isRef() and

View File

@@ -6,7 +6,7 @@ import csharp
from DelegateType d
where
d.hasQualifiedName("System.Threading.ContextCallback") and
d.hasQualifiedName("System.Threading", "ContextCallback") and
d.getNumberOfParameters() = 1 and
d.getParameter(0).hasName("state") and
d.getParameter(0).isValue() and

View File

@@ -7,5 +7,5 @@ import csharp
from EnumConstant c
where
c.getName() = "Red" and
c.getDeclaringType().hasQualifiedName("Enums.Color")
c.getDeclaringType().hasQualifiedName("Enums", "Color")
select c, c.getType()

View File

@@ -8,7 +8,7 @@ from EnumConstant c, EnumConstant d
where
c.getName() = "Blue" and
d.hasName("AnotherBlue") and
c.getDeclaringType().hasQualifiedName("Enums.SparseColor") and
c.getDeclaringType().hasQualifiedName("Enums", "SparseColor") and
c.getType() = c.getDeclaringType() and
c.getType() = d.getType() and
c.getValue() = "11" and

View File

@@ -7,7 +7,7 @@ import csharp
from EnumConstant c
where
c.getName() = "Green" and
c.getDeclaringType().hasQualifiedName("Enums.Color") and
c.getDeclaringType().hasQualifiedName("Enums", "Color") and
c.getType() = c.getDeclaringType() and
c.getUnderlyingType() instanceof IntType
select c

View File

@@ -7,7 +7,7 @@ import csharp
from EnumConstant c
where
c.getName() = "Green" and
c.getDeclaringType().hasQualifiedName("Enums.LongColor") and
c.getDeclaringType().hasQualifiedName("Enums", "LongColor") and
c.getType() = c.getDeclaringType() and
c.getValue() = "1"
select c, c.getDeclaringType().getBaseClass().getQualifiedName()

View File

@@ -4,5 +4,5 @@
import csharp
where forall(Enum e | e.getBaseClass().hasQualifiedName("System.Enum"))
where forall(Enum e | e.getBaseClass().hasQualifiedName("System", "Enum"))
select 1

View File

@@ -7,7 +7,7 @@ import csharp
from EnumConstant c
where
c.getName() = "FourBlue" and
c.getDeclaringType().hasQualifiedName("Enums.ValueColor") and
c.getDeclaringType().hasQualifiedName("Enums", "ValueColor") and
c.getType() = c.getDeclaringType() and
c.getValue() = "4" and
c.getUnderlyingType() instanceof UIntType

View File

@@ -7,7 +7,7 @@ import csharp
from EnumConstant c
where
c.getName() = "FourBlue" and
c.getDeclaringType().hasQualifiedName("Enums.ValueColor") and
c.getDeclaringType().hasQualifiedName("Enums", "ValueColor") and
c.getType() = c.getDeclaringType() and
c.getValue() = "4" and
c.getUnderlyingType() instanceof UIntType

View File

@@ -7,7 +7,7 @@ import csharp
from EnumConstant c
where
c.getName() = "Red" and
c.getDeclaringType().hasQualifiedName("Enums.SparseColor") and
c.getDeclaringType().hasQualifiedName("Enums", "SparseColor") and
c.getType() = c.getDeclaringType() and
c.getValue() = "0" and
c.getUnderlyingType() instanceof IntType and

View File

@@ -7,7 +7,7 @@ import csharp
from EnumConstant c
where
c.getName() = "Green" and
c.getDeclaringType().hasQualifiedName("Enums.SparseColor") and
c.getDeclaringType().hasQualifiedName("Enums", "SparseColor") and
c.getType() = c.getDeclaringType() and
c.getValue() = "10" and
c.getUnderlyingType() instanceof IntType and

View File

@@ -7,6 +7,6 @@ import csharp
from Event e
where
e.getName() = "Click" and
e.getDeclaringType().hasQualifiedName("Events.Button") and
e.getDeclaringType().hasQualifiedName("Events", "Button") and
e.isPublic()
select e, e.getType()

View File

@@ -7,6 +7,6 @@ import csharp
from Event e
where
e.getName() = "Click" and
e.getDeclaringType().hasQualifiedName("Events.Button") and
e.getDeclaringType().hasQualifiedName("Events", "Button") and
e.isFieldLike()
select e, e.getType()

View File

@@ -7,6 +7,6 @@ import csharp
from Event e
where
e.getName() = "Click" and
e.getDeclaringType().hasQualifiedName("Events.Button") and
e.getDeclaringType().hasQualifiedName("Events", "Button") and
e.getType().hasName("EventHandler")
select e, e.getType()

View File

@@ -7,7 +7,7 @@ import csharp
from Event e
where
e.getName() = "MouseUp" and
e.getDeclaringType().hasQualifiedName("Events.Control") and
e.getDeclaringType().hasQualifiedName("Events", "Control") and
e.getType().hasName("EventHandler") and
e.isPublic()
select e, e.getType()

View File

@@ -6,7 +6,7 @@ import csharp
where
count(Event e |
e.getDeclaringType().hasQualifiedName("Events.Control") and
e.getDeclaringType().hasQualifiedName("Events", "Control") and
e.getType().hasName("EventHandler") and
e.isPublic()
) = 2

View File

@@ -7,6 +7,6 @@ import csharp
from Event e
where
e.getName() = "MouseUp" and
e.getDeclaringType().hasQualifiedName("Events.Control") and
e.getDeclaringType().hasQualifiedName("Events", "Control") and
not e.isFieldLike()
select e, e.getType()

View File

@@ -9,6 +9,6 @@ where
m.hasName("MainIsAsCast") and
e.getEnclosingCallable() = m and
e.getExpr().(ParameterAccess).getTarget().getName() = "o" and
e.getTargetType().(Class).hasQualifiedName("Expressions.Class") and
e.getTargetType().(Class).hasQualifiedName("Expressions", "Class") and
e.getEnclosingStmt().getParent().getParent() instanceof IfStmt
select m, e

View File

@@ -9,6 +9,6 @@ where
m.hasName("MainIsAsCast") and
e.getEnclosingCallable() = m and
e.getExpr().(ParameterAccess).getTarget().getName() = "p" and
e.getTargetType().(Class).hasQualifiedName("Expressions.Class") and
e.getTargetType().(Class).hasQualifiedName("Expressions", "Class") and
e.getEnclosingStmt().getParent().getParent() instanceof IfStmt
select m, e

View File

@@ -10,5 +10,5 @@ where
e.getEnclosingCallable() = m and
e.getExpr() = a and
a.getTarget().hasName("cd7") and
a.getTarget().getType().(DelegateType).hasQualifiedName("Expressions.D")
a.getTarget().getType().(DelegateType).hasQualifiedName("Expressions", "D")
select m, e, a

View File

@@ -10,5 +10,5 @@ where
e.getEnclosingCallable() = m and
e.getExpr().(ParameterAccess).getTarget().getName() = "o" and
tpe = e.getPattern() and
tpe.getCheckedType().(Class).hasQualifiedName("Expressions.Class")
tpe.getCheckedType().(Class).hasQualifiedName("Expressions", "Class")
select m, e

View File

@@ -7,7 +7,7 @@ import csharp
from MemberConstant c
where
c.getName() = "X" and
c.getDeclaringType().hasQualifiedName("Constants.A") and
c.getDeclaringType().hasQualifiedName("Constants", "A") and
c.getType() instanceof IntType and
c.getInitializer() instanceof BinaryOperation and
c.isPublic() and

View File

@@ -7,7 +7,7 @@ import csharp
from MemberConstant c
where
c.getName() = "Y" and
c.getDeclaringType().hasQualifiedName("Constants.A") and
c.getDeclaringType().hasQualifiedName("Constants", "A") and
c.getType() instanceof IntType and
c.getInitializer() instanceof IntLiteral and
c.isPublic() and

View File

@@ -7,7 +7,7 @@ import csharp
from MemberConstant c
where
c.getName() = "Z" and
c.getDeclaringType().hasQualifiedName("Constants.B") and
c.getDeclaringType().hasQualifiedName("Constants", "B") and
c.getType() instanceof IntType and
c.getInitializer() instanceof BinaryOperation and
c.isPublic() and

View File

@@ -7,7 +7,7 @@ import csharp
from Field f
where
f.getName() = "X" and
f.getDeclaringType().hasQualifiedName("Fields.A") and
f.getDeclaringType().hasQualifiedName("Fields", "A") and
f.getType() instanceof IntType and
f.getInitializer().(IntLiteral).getValue() = "1" and
f.isPublic() and

View File

@@ -8,6 +8,6 @@ from Field f, SimpleType t
where
f.getName() = "MaxValue" and
f.getDeclaringType() = t and
t.hasQualifiedName("System.Decimal") and
t.hasQualifiedName("System", "Decimal") and
f.isPublic()
select f.toString(), f.getDeclaringType().toString()

View File

@@ -7,7 +7,7 @@ import csharp
from Field f
where
f.getName() = "Y" and
f.getDeclaringType().hasQualifiedName("Fields.A") and
f.getDeclaringType().hasQualifiedName("Fields", "A") and
f.getType() instanceof IntType and
not exists(f.getInitializer()) and
f.isPublic() and

View File

@@ -7,7 +7,7 @@ import csharp
from Field f
where
f.getName() = "Z" and
f.getDeclaringType().hasQualifiedName("Fields.A") and
f.getDeclaringType().hasQualifiedName("Fields", "A") and
f.getType() instanceof IntType and
f.getInitializer().(IntLiteral).getValue() = "100" and
f.isPublic() and

View File

@@ -7,7 +7,7 @@ import csharp
from Field f
where
f.getName() = "X" and
f.getDeclaringType().hasQualifiedName("Fields.B") and
f.getDeclaringType().hasQualifiedName("Fields", "B") and
f.getType() instanceof IntType and
f.getInitializer().(IntLiteral).getValue() = "1" and
f.isPublic() and

View File

@@ -7,7 +7,7 @@ import csharp
from Field f
where
f.getName() = "Y" and
f.getDeclaringType().hasQualifiedName("Fields.B") and
f.getDeclaringType().hasQualifiedName("Fields", "B") and
f.getType() instanceof IntType and
not exists(f.getInitializer()) and
f.isPublic() and

View File

@@ -7,7 +7,7 @@ import csharp
from Field f
where
f.getName() = "finished" and
f.getDeclaringType().hasQualifiedName("Fields.Application") and
f.getDeclaringType().hasQualifiedName("Fields", "Application") and
f.getType() instanceof BoolType and
not exists(f.getInitializer()) and
f.isPublic() and

View File

@@ -8,7 +8,7 @@ from Field f, UnboundGenericClass c
where
f.getName() = "count" and
f.getDeclaringType() = c and
c.hasQualifiedName("Fields.C<>") and
c.hasQualifiedName("Fields", "C<>") and
f.getType() instanceof IntType and
f.isStatic()
select f, f.getDeclaringType()

View File

@@ -8,7 +8,7 @@ from Field f, UnboundGenericClass c
where
f.getName() = "count" and
f.getDeclaringType() = c and
c.hasQualifiedName("Fields.C<>") and
c.hasQualifiedName("Fields", "C<>") and
f.getType() instanceof IntType and
f.isStatic()
select f, f.getDeclaringType()

View File

@@ -8,7 +8,7 @@ from Field f, Class c
where
f.getName() = "Black" and
f.getDeclaringType() = c and
c.hasQualifiedName("Fields.Color") and
c.hasQualifiedName("Fields", "Color") and
f.getType() = c and
f.isStatic() and
f.isPublic() and

View File

@@ -6,7 +6,7 @@ import csharp
from Indexer i
where
i.getDeclaringType().hasQualifiedName("Indexers.Grid") and
i.getDeclaringType().hasQualifiedName("Indexers", "Grid") and
i.getType() instanceof IntType and
i.isPublic() and
i.isReadWrite()

View File

@@ -6,7 +6,7 @@ import csharp
from Indexer i
where
i.getDeclaringType().hasQualifiedName("Indexers.BitArray") and
i.getDeclaringType().hasQualifiedName("Indexers", "BitArray") and
i.getType() instanceof BoolType and
i.getDimension() = 1
select i

View File

@@ -6,7 +6,7 @@ import csharp
from Indexer i
where
i.getDeclaringType().hasQualifiedName("Indexers.BitArray") and
i.getDeclaringType().hasQualifiedName("Indexers", "BitArray") and
i.getType() instanceof BoolType and
i.getParameter(0).getName() = "index" and
i.getParameter(0).getType() instanceof IntType

View File

@@ -6,6 +6,6 @@ import csharp
from Class c
where
c.hasQualifiedName("Indexers.BitArray") and
c.hasQualifiedName("Indexers", "BitArray") and
count(Indexer i | i.getDeclaringType() = c) = 1
select c

View File

@@ -6,7 +6,7 @@ import csharp
from Indexer i
where
i.getDeclaringType().hasQualifiedName("Indexers.BitArray") and
i.getDeclaringType().hasQualifiedName("Indexers", "BitArray") and
i.getType() instanceof BoolType and
i.isPublic() and
i.isReadWrite()

View File

@@ -6,7 +6,7 @@ import csharp
from Indexer i
where
i.getDeclaringType().hasQualifiedName("Indexers.BitArray") and
i.getDeclaringType().hasQualifiedName("Indexers", "BitArray") and
i.getType() instanceof BoolType and
i.getGetter().hasBody() and
i.getSetter().hasBody()

View File

@@ -6,7 +6,7 @@ import csharp
from Indexer i
where
i.getDeclaringType().hasQualifiedName("Indexers.Grid") and
i.getDeclaringType().hasQualifiedName("Indexers", "Grid") and
i.getType() instanceof IntType and
i.getDimension() = 2
select i

Some files were not shown because too many files have changed in this diff Show More