Skip to content

Commit 8a81d42

Browse files
committed
Python: more logic adjustment
Not sure why the missing result is missing. There is and edge with label `getAwaited` from `pkg.async_func` on line 22 to `coro` on line 23.
1 parent f91e43c commit 8a81d42

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -494,26 +494,26 @@ module API {
494494
// - `awaitedValue` is `x`
495495
// - `result` is `await x`
496496
exists(Await await |
497-
result.asExpr() = await and
498-
await.getValue() = awaitedValue.asExpr()
497+
await.getValue() = awaitedValue.asExpr() and
498+
result.asExpr() = await
499499
)
500500
or
501501
// `async for x in l`
502502
// - `awaitedValue` is `l`
503-
// - `result` is `l` (should perhaps be `x`, but that should really be a read)
503+
// - `result` is `l` (`x` is behind a read step)
504504
exists(AsyncFor asyncFor |
505-
result.asExpr() = asyncFor.getIter() and
506505
// To consider `x` the result of awaiting, we would use asyncFor.getTarget() = awaitedValue.asExpr(),
507506
// but that is behind a read step rather than a flow step.
508-
asyncFor.getIter() = awaitedValue.asExpr()
507+
asyncFor.getIter() = awaitedValue.asExpr() and
508+
result.asExpr() = asyncFor.getIter()
509509
)
510510
or
511511
// `async with x as y`
512512
// - `awaitedValue` is `x`
513513
// - `result` is `x` and `y` if it exists
514514
exists(AsyncWith asyncWith |
515-
result.asExpr() = asyncWith.getContextExpr() and
516-
awaitedValue.asExpr() in [
515+
awaitedValue.asExpr() = asyncWith.getContextExpr() and
516+
result.asExpr() in [
517517
// `x`
518518
asyncWith.getContextExpr(),
519519
// `y`, if it exists

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,26 +75,26 @@ private module Asyncpg {
7575
// - `awaitedValue` is `x`
7676
// - `result` is `await x`
7777
exists(Await await |
78-
result.asExpr() = await and
79-
await.getValue() = awaitedValue.asExpr()
78+
await.getValue() = awaitedValue.asExpr() and
79+
result.asExpr() = await
8080
)
8181
or
8282
// `async for x in l`
8383
// - `awaitedValue` is local source of `l`
8484
// - `result` is `l`
8585
exists(AsyncFor asyncFor, DataFlow::Node awaited |
86-
result.asExpr() = asyncFor.getIter() and
8786
asyncFor.getIter() = awaited.asExpr() and
88-
awaited.getALocalSource() = awaitedValue
87+
awaited.getALocalSource() = awaitedValue and
88+
result.asExpr() = asyncFor.getIter()
8989
)
9090
or
9191
// `async with x as y`
9292
// - `awaitedValue` is local source of `x`
9393
// - `result` is `x` and `y`
9494
exists(AsyncWith asyncWith, DataFlow::Node awaited |
95-
result.asExpr() = asyncWith.getContextExpr() and
96-
awaited.asExpr() in [asyncWith.getContextExpr(), asyncWith.getOptionalVars()] and
97-
awaited.getALocalSource() = awaitedValue
95+
awaited.asExpr() = asyncWith.getContextExpr() and
96+
awaited.getALocalSource() = awaitedValue and
97+
result.asExpr() in [asyncWith.getContextExpr(), asyncWith.getOptionalVars()]
9898
)
9999
}
100100

python/ql/test/experimental/dataflow/ApiGraphs/async_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ async def bar():
1212
return result # $ use=moduleImport("pkg").getMember("async_func").getReturn().getAwaited() awaited=moduleImport("pkg").getMember("async_func").getReturn()
1313

1414
async def test_async_with():
15-
async with pkg.async_func() as result: # $ use=moduleImport("pkg").getMember("async_func").getReturn() awaited=moduleImport("pkg").getMember("async_func").getReturn()
15+
async with pkg.async_func() as result: # $ use=moduleImport("pkg").getMember("async_func").getReturn().getAwaited() awaited=moduleImport("pkg").getMember("async_func").getReturn()
1616
return result # $ use=moduleImport("pkg").getMember("async_func").getReturn() awaited=moduleImport("pkg").getMember("async_func").getReturn()
1717

1818
async def test_async_for():

0 commit comments

Comments
 (0)