-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathAwaited.qll
More file actions
51 lines (49 loc) · 1.34 KB
/
Awaited.qll
File metadata and controls
51 lines (49 loc) · 1.34 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
/**
* INTERNAL: Do not use.
*
* Provides helper class for defining additional API graph edges.
*/
overlay[local]
module;
private import python
private import semmle.python.dataflow.new.DataFlow
private import semmle.python.internal.CachedStages
/**
* INTERNAL: Do not use.
*
* Holds if `result` is the result of awaiting `awaitedValue`.
*/
cached
DataFlow::Node awaited(DataFlow::Node awaitedValue) {
Stages::DataFlow::ref() and
// `await` x
// - `awaitedValue` is `x`
// - `result` is `await x`
exists(Await await |
await.getValue() = awaitedValue.asExpr() and
result.asExpr() = await
)
or
// `async for x in l`
// - `awaitedValue` is `l`
// - `result` is `l` (`x` is behind a read step)
exists(AsyncFor asyncFor |
// To consider `x` the result of awaiting, we would use asyncFor.getTarget() = awaitedValue.asExpr(),
// but that is behind a read step rather than a flow step.
asyncFor.getIter() = awaitedValue.asExpr() and
result.asExpr() = asyncFor.getIter()
)
or
// `async with x as y`
// - `awaitedValue` is `x`
// - `result` is `x` and `y` if it exists
exists(AsyncWith asyncWith |
awaitedValue.asExpr() = asyncWith.getContextExpr() and
result.asExpr() in [
// `x`
asyncWith.getContextExpr(),
// `y`, if it exists
asyncWith.getOptionalVars()
]
)
}