mirror of
https://github.com/github/codeql.git
synced 2026-04-28 02:05:14 +02:00
C#: Address review comments.
This commit is contained in:
@@ -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