mirror of
https://github.com/github/codeql.git
synced 2026-05-11 09:49:26 +02:00
Python: adjust logic and add tests
Due to the way paths a re printed, the tests look surprising
This commit is contained in:
@@ -502,20 +502,23 @@ module API {
|
||||
// - `awaitedValue` is `l`
|
||||
// - `result` is `l` (should perhaps be `x`, but that should really be a read)
|
||||
exists(AsyncFor asyncFor |
|
||||
result.asExpr() = asyncFor.getTarget() and
|
||||
// Morally, we should perhaps use asyncFor.getIter() = awaitedValue.asExpr(),
|
||||
// but that is actually behind a read step rather than a flow step.
|
||||
asyncFor.getTarget() = awaitedValue.asExpr()
|
||||
result.asExpr() = asyncFor.getIter() and
|
||||
// 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()
|
||||
)
|
||||
or
|
||||
// `async with x as y`
|
||||
// - `awaitedValue` is `x`
|
||||
// - `result` is `x` (should probably be `y` but it might not exist)
|
||||
// - `result` is `x` and `y` if it exists
|
||||
exists(AsyncWith asyncWith |
|
||||
result.asExpr() = asyncWith.getContextExpr() and
|
||||
// Morally, we should perhaps use asyncWith.getOptionalVars() = awaitedValue.asExpr(),
|
||||
// but that might not exist.
|
||||
asyncWith.getContextExpr() = awaitedValue.asExpr()
|
||||
awaitedValue.asExpr() in [
|
||||
// `x`
|
||||
asyncWith.getContextExpr(),
|
||||
// `y`, if it exists
|
||||
asyncWith.getOptionalVars()
|
||||
]
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -83,17 +83,17 @@ private module Asyncpg {
|
||||
// - `awaitedValue` is local source of `l`
|
||||
// - `result` is `l`
|
||||
exists(AsyncFor asyncFor, DataFlow::Node awaited |
|
||||
result.asExpr() = asyncFor.getTarget() and
|
||||
result.asExpr() = asyncFor.getIter() and
|
||||
asyncFor.getIter() = awaited.asExpr() and
|
||||
awaited.getALocalSource() = awaitedValue
|
||||
)
|
||||
or
|
||||
// `async with x as y`
|
||||
// - `awaitedValue` is local source of `x`
|
||||
// - `result` is `x`
|
||||
// - `result` is `x` and `y`
|
||||
exists(AsyncWith asyncWith, DataFlow::Node awaited |
|
||||
result.asExpr() = asyncWith.getContextExpr() and
|
||||
asyncWith.getOptionalVars() = awaited.asExpr() and
|
||||
awaited.asExpr() in [asyncWith.getContextExpr(), asyncWith.getOptionalVars()] and
|
||||
awaited.getALocalSource() = awaitedValue
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user