Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a5912ff

Browse files
committed
Python: Align implementations of awaited.
1 parent 3c1206f commit a5912ff

2 files changed

Lines changed: 18 additions & 16 deletions

File tree

python/ql/lib/semmle/python/ApiGraphs.qll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -500,21 +500,21 @@ module API {
500500
or
501501
// `async for x in l`
502502
// - `awaitedValue` is `l`
503-
// - `result` is `l` (should perhaps be `x`)
503+
// - `result` is `l` (should perhaps be `x`, but that should really be a read)
504504
exists(AsyncFor asyncFor |
505505
result.asExpr() = asyncFor.getTarget() and
506-
// Morally, we should perhaps use asyncFor.getIter() = awaitedValue.asExpr()
507-
// but that does not work.
506+
// Morally, we should perhaps use asyncFor.getIter() = awaitedValue.asExpr(),
507+
// but that is actually behind a read step rather than a flow step.
508508
asyncFor.getTarget() = awaitedValue.asExpr()
509509
)
510510
or
511511
// `async with x as y`
512512
// - `awaitedValue` is `x`
513-
// - `result` is `x` (should probably be `y`)
513+
// - `result` is `x` (should probably be `y` but it might not exist)
514514
exists(AsyncWith asyncWith |
515515
result.asExpr() = asyncWith.getContextExpr() and
516-
// Morally, we should perhaps use asyncWith.getOptionalVars() = awaitedValue.asExpr()
517-
// but that does not work.
516+
// Morally, we should perhaps use asyncWith.getOptionalVars() = awaitedValue.asExpr(),
517+
// but that might not exist.
518518
asyncWith.getContextExpr() = awaitedValue.asExpr()
519519
)
520520
}

python/ql/lib/semmle/python/frameworks/Asyncpg.qll

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,29 +42,31 @@ private module Asyncpg {
4242
* Holds if `result` is the result of awaiting `n`.
4343
*/
4444
pragma[inline]
45-
DataFlow::Node awaited(DataFlow::Node n) {
45+
DataFlow::Node awaited(DataFlow::Node awaitedValue) {
4646
// `await` x
4747
// - `awaitedValue` is `x`
4848
// - `result` is `await x`
4949
exists(Await await |
5050
result.asExpr() = await and
51-
await.getValue() = n.asExpr()
51+
await.getValue() = awaitedValue.asExpr()
5252
)
5353
or
5454
// `async for x in l`
55-
// - `awaitedValue` is `l`
56-
// - `result` is `x`
57-
exists(AsyncFor asyncFor |
55+
// - `awaitedValue` is local source of `l`
56+
// - `result` is `l`
57+
exists(AsyncFor asyncFor, DataFlow::Node awaited |
5858
result.asExpr() = asyncFor.getTarget() and
59-
asyncFor.getIter() = n.asExpr()
59+
asyncFor.getIter() = awaited.asExpr() and
60+
awaited.getALocalSource() = awaitedValue
6061
)
6162
or
6263
// `async with x as y`
63-
// - `awaitedValue` is `x`
64-
// - `result` is `y`
65-
exists(AsyncWith asyncWith |
64+
// - `awaitedValue` is local source of `x`
65+
// - `result` is `x`
66+
exists(AsyncWith asyncWith, DataFlow::Node awaited |
6667
result.asExpr() = asyncWith.getContextExpr() and
67-
asyncWith.getOptionalVars() = n.asExpr()
68+
asyncWith.getOptionalVars() = awaited.asExpr() and
69+
awaited.getALocalSource() = awaitedValue
6870
)
6971
}
7072

0 commit comments

Comments
 (0)