forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathStdlib.qll
More file actions
308 lines (265 loc) · 7.91 KB
/
Stdlib.qll
File metadata and controls
308 lines (265 loc) · 7.91 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
/**
* Provides classes modeling security-relevant aspects of the standard libraries.
*/
private import rust
private import codeql.rust.Concepts
private import codeql.rust.controlflow.ControlFlowGraph as Cfg
private import codeql.rust.controlflow.CfgNodes as CfgNodes
private import codeql.rust.dataflow.DataFlow
private import codeql.rust.internal.PathResolution
/**
* A call to the `starts_with` method on a `Path`.
*/
private class StartswithCall extends Path::SafeAccessCheck::Range, CfgNodes::MethodCallExprCfgNode {
StartswithCall() {
this.getMethodCallExpr().getStaticTarget().getCanonicalPath() = "<std::path::Path>::starts_with"
}
override predicate checks(Cfg::CfgNode e, boolean branch) {
e = this.getReceiver() and
branch = true
}
}
/**
* The [`Option` enum][1].
*
* [1]: https://doc.rust-lang.org/std/option/enum.Option.html
*/
class OptionEnum extends Enum {
pragma[nomagic]
OptionEnum() { this.getCanonicalPath() = "core::option::Option" }
/** Gets the `Some` variant. */
Variant getSome() { result = this.getVariant("Some") }
}
/**
* The [`Result` enum][1].
*
* [1]: https://doc.rust-lang.org/stable/std/result/enum.Result.html
*/
class ResultEnum extends Enum {
pragma[nomagic]
ResultEnum() { this.getCanonicalPath() = "core::result::Result" }
/** Gets the `Ok` variant. */
Variant getOk() { result = this.getVariant("Ok") }
/** Gets the `Err` variant. */
Variant getErr() { result = this.getVariant("Err") }
}
/**
* The [`Range` struct][1].
*
* [1]: https://doc.rust-lang.org/core/ops/struct.Range.html
*/
class RangeStruct extends Struct {
pragma[nomagic]
RangeStruct() { this.getCanonicalPath() = "core::ops::range::Range" }
/** Gets the `start` field. */
StructField getStart() { result = this.getStructField("start") }
/** Gets the `end` field. */
StructField getEnd() { result = this.getStructField("end") }
}
/**
* The [`RangeFrom` struct][1].
*
* [1]: https://doc.rust-lang.org/core/ops/struct.RangeFrom.html
*/
class RangeFromStruct extends Struct {
pragma[nomagic]
RangeFromStruct() { this.getCanonicalPath() = "core::ops::range::RangeFrom" }
/** Gets the `start` field. */
StructField getStart() { result = this.getStructField("start") }
}
/**
* The [`RangeTo` struct][1].
*
* [1]: https://doc.rust-lang.org/core/ops/struct.RangeTo.html
*/
class RangeToStruct extends Struct {
pragma[nomagic]
RangeToStruct() { this.getCanonicalPath() = "core::ops::range::RangeTo" }
/** Gets the `end` field. */
StructField getEnd() { result = this.getStructField("end") }
}
/**
* The [`RangeFull` struct][1].
*
* [1]: https://doc.rust-lang.org/core/ops/struct.RangeFull.html
*/
class RangeFullStruct extends Struct {
pragma[nomagic]
RangeFullStruct() { this.getCanonicalPath() = "core::ops::range::RangeFull" }
}
/**
* The [`RangeInclusive` struct][1].
*
* [1]: https://doc.rust-lang.org/core/ops/struct.RangeInclusive.html
*/
class RangeInclusiveStruct extends Struct {
pragma[nomagic]
RangeInclusiveStruct() { this.getCanonicalPath() = "core::ops::range::RangeInclusive" }
/** Gets the `start` field. */
StructField getStart() { result = this.getStructField("start") }
/** Gets the `end` field. */
StructField getEnd() { result = this.getStructField("end") }
}
/**
* The [`RangeToInclusive` struct][1].
*
* [1]: https://doc.rust-lang.org/core/ops/struct.RangeToInclusive.html
*/
class RangeToInclusiveStruct extends Struct {
pragma[nomagic]
RangeToInclusiveStruct() { this.getCanonicalPath() = "core::ops::range::RangeToInclusive" }
/** Gets the `end` field. */
StructField getEnd() { result = this.getStructField("end") }
}
/**
* The [`Future` trait][1].
*
* [1]: https://doc.rust-lang.org/std/future/trait.Future.html
*/
class FutureTrait extends Trait {
pragma[nomagic]
FutureTrait() { this.getCanonicalPath() = "core::future::future::Future" }
/** Gets the `Output` associated type. */
pragma[nomagic]
TypeAlias getOutputType() {
result = this.getAssocItemList().getAnAssocItem() and
result.getName().getText() = "Output"
}
}
/**
* The [`FnOnce` trait][1].
*
* [1]: https://doc.rust-lang.org/std/ops/trait.FnOnce.html
*/
class FnOnceTrait extends Trait {
pragma[nomagic]
FnOnceTrait() { this.getCanonicalPath() = "core::ops::function::FnOnce" }
/** Gets the type parameter of this trait. */
TypeParam getTypeParam() { result = this.getGenericParamList().getGenericParam(0) }
/** Gets the `Output` associated type. */
pragma[nomagic]
TypeAlias getOutputType() {
result = this.getAssocItemList().getAnAssocItem() and
result.getName().getText() = "Output"
}
}
/**
* The [`Iterator` trait][1].
*
* [1]: https://doc.rust-lang.org/std/iter/trait.Iterator.html
*/
class IteratorTrait extends Trait {
pragma[nomagic]
IteratorTrait() { this.getCanonicalPath() = "core::iter::traits::iterator::Iterator" }
/** Gets the `Item` associated type. */
pragma[nomagic]
TypeAlias getItemType() {
result = this.getAssocItemList().getAnAssocItem() and
result.getName().getText() = "Item"
}
}
/**
* The [`IntoIterator` trait][1].
*
* [1]: https://doc.rust-lang.org/std/iter/trait.IntoIterator.html
*/
class IntoIteratorTrait extends Trait {
pragma[nomagic]
IntoIteratorTrait() { this.getCanonicalPath() = "core::iter::traits::collect::IntoIterator" }
/** Gets the `Item` associated type. */
pragma[nomagic]
TypeAlias getItemType() {
result = this.getAssocItemList().getAnAssocItem() and
result.getName().getText() = "Item"
}
}
/**
* The [`String` struct][1].
*
* [1]: https://doc.rust-lang.org/std/string/struct.String.html
*/
class StringStruct extends Struct {
pragma[nomagic]
StringStruct() { this.getCanonicalPath() = "alloc::string::String" }
}
/**
* The [`Deref` trait][1].
*
* [1]: https://doc.rust-lang.org/core/ops/trait.Deref.html
*/
class DerefTrait extends Trait {
pragma[nomagic]
DerefTrait() { this.getCanonicalPath() = "core::ops::deref::Deref" }
/** Gets the `deref` function. */
Function getDerefFunction() { result = this.(TraitItemNode).getAssocItem("deref") }
/** Gets the `Target` associated type. */
pragma[nomagic]
TypeAlias getTargetType() {
result = this.getAssocItemList().getAnAssocItem() and
result.getName().getText() = "Target"
}
}
/**
* The [`Index` trait][1].
*
* [1]: https://doc.rust-lang.org/std/ops/trait.Index.html
*/
class IndexTrait extends Trait {
pragma[nomagic]
IndexTrait() { this.getCanonicalPath() = "core::ops::index::Index" }
/** Gets the `index` function. */
Function getIndexFunction() { result = this.(TraitItemNode).getAssocItem("index") }
/** Gets the `Output` associated type. */
pragma[nomagic]
TypeAlias getOutputType() {
result = this.getAssocItemList().getAnAssocItem() and
result.getName().getText() = "Output"
}
}
/**
* The [`Box` struct][1].
*
* [1]: https://doc.rust-lang.org/std/boxed/struct.Box.html
*/
class BoxStruct extends Struct {
pragma[nomagic]
BoxStruct() { this.getCanonicalPath() = "alloc::boxed::Box" }
}
/**
* The [`Rc` struct][1].
*
* [1]: https://doc.rust-lang.org/std/rc/struct.Rc.html
*/
class RcStruct extends Struct {
pragma[nomagic]
RcStruct() { this.getCanonicalPath() = "alloc::rc::Rc" }
}
/**
* The [`Arc` struct][1].
*
* [1]: https://doc.rust-lang.org/std/sync/struct.Arc.html
*/
class ArcStruct extends Struct {
pragma[nomagic]
ArcStruct() { this.getCanonicalPath() = "alloc::sync::Arc" }
}
/**
* The [`Pin` struct][1].
*
* [1]: https://doc.rust-lang.org/std/pin/struct.Pin.html
*/
class PinStruct extends Struct {
pragma[nomagic]
PinStruct() { this.getCanonicalPath() = "core::pin::Pin" }
}
/**
* The [`Vec` struct][1].
*
* [1]: https://doc.rust-lang.org/alloc/vec/struct.Vec.html
*/
class Vec extends Struct {
pragma[nomagic]
Vec() { this.getCanonicalPath() = "alloc::vec::Vec" }
/** Gets the type parameter representing the element type. */
TypeParam getElementTypeParam() { result = this.getGenericParamList().getTypeParam(0) }
}