-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathDataSetSerialization.qll
More file actions
110 lines (102 loc) · 3.7 KB
/
DataSetSerialization.qll
File metadata and controls
110 lines (102 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import csharp
/**
* Abstract class thats depnds or inherits from DataSet and DataTable types.
**/
abstract class DataSetOrTableRelatedClass extends Class {
}
/**
* Gets the DataSet and DataTable types, or types derived from them.
**/
class DataSetOrTable extends DataSetOrTableRelatedClass {
DataSetOrTable() {
this.getABaseType*().getQualifiedName().matches("System.Data.DataTable") or
this.getABaseType*().getQualifiedName().matches("System.Data.DataSet") or
this.getQualifiedName().matches("System.Data.DataTable") or
this.getQualifiedName().matches("System.Data.DataSet")
}
}
/**
* Gets a class that include a property or generic of type DataSet and DataTable
*/
class ClassWithDataSetOrTableMember extends DataSetOrTableRelatedClass {
ClassWithDataSetOrTableMember() {
exists( Property p |
p = this.getAProperty() |
p.getType() instanceof DataSetOrTable
) or exists ( AssignableMember am |
am = this.getAField() or
am = this.getAMember() |
am.getType() instanceof DataSetOrTable
) or exists( Property p |
p = this.getAProperty() |
p.getType() instanceof DataSetOrTable or
p.getType().(ConstructedGeneric).getATypeArgument() instanceof DataSetOrTable
)
}
}
/**
* Serializable types
*/
class SerializableClass extends Class {
SerializableClass() {
(
this.getABaseType*().getQualifiedName().matches("System.Xml.Serialization.XmlSerializer") or
this.getABaseInterface*().getQualifiedName().matches("System.Runtime.Serialization.ISerializable") or
this.getABaseType*().getQualifiedName().matches("System.Runtime.Serialization.XmlObjectSerializer") or
this.getABaseInterface*().getQualifiedName().matches("System.Runtime.Serialization.ISerializationSurrogateProvider") or
this.getABaseType*().getQualifiedName().matches("System.Runtime.Serialization.XmlSerializableServices") or
this.getABaseInterface*().getQualifiedName().matches("System.Xml.Serialization.IXmlSerializable")
) or exists( Attribute a |
a = this.getAnAttribute() |
a.getType().getQualifiedName().toString() = "System.SerializableAttribute"
)
}
}
predicate isClassUnsafeXmlSerializerImplementation( SerializableClass c, Member m) {
exists( Property p |
m = p |
p = c.getAProperty() and
p.getType() instanceof DataSetOrTableRelatedClass
) or exists ( AssignableMember am |
am = m |
( am = c.getAField() or am = c.getAMember() ) and
am.getType() instanceof DataSetOrTableRelatedClass
)
}
/**
* It is unsafe to serilize DataSet and DataTable related types
*/
class UnsafeXmlSerializerImplementation extends SerializableClass {
UnsafeXmlSerializerImplementation() {
isClassUnsafeXmlSerializerImplementation( this, _ )
}
}
/**
* Method that may be unsafe when used to serialize DataSet and DataTable related types
*/
class UnsafeXmlReadMethod extends Method {
UnsafeXmlReadMethod() {
this.getQualifiedName().toString() = "System.Data.DataTable.ReadXml" or
this.getQualifiedName().toString() = "System.Data.DataTable.ReadXmlSchema" or
this.getQualifiedName().toString() = "System.Data.DataSet.ReadXml" or
this.getQualifiedName().toString() = "System.Data.DataSet.ReadXmlSchema" or
(
this.getName().matches("ReadXml%") and
exists( Class c |
c.getAMethod() = this |
c.getABaseType*() instanceof DataSetOrTableRelatedClass or
c.getABaseType*() instanceof DataSetOrTableRelatedClass
)
)
}
}
/**
* MethodCal that may be unsafe when used to serialize DataSet and DataTable related types
*/
class UnsafeXmlReadMethodCall extends MethodCall {
UnsafeXmlReadMethodCall() {
exists( UnsafeXmlReadMethod uxrm |
uxrm.getACall() = this
)
}
}