Skip to content

Commit 7efb4ab

Browse files
authored
Merge pull request #8581 from tausbn/python-fix-bad-join-in-import_star_read
Python: Fix bad join in `import_star_read`
2 parents d1cc835 + 95d2354 commit 7efb4ab

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

python/ql/lib/semmle/python/Exprs.qll

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,16 @@ class Call extends Call_ {
189189
*/
190190
Keyword getKeyword(int index) {
191191
result = this.getNamedArg(index) and
192-
not exists(DictUnpacking d, int lower | d = this.getNamedArg(lower) and lower < index)
192+
(
193+
not exists(this.getMinimumUnpackingIndex())
194+
or
195+
index <= this.getMinimumUnpackingIndex()
196+
)
197+
}
198+
199+
/** Gets the minimum index (if any) at which a dictionary unpacking (`**foo`) occurs in this call. */
200+
private int getMinimumUnpackingIndex() {
201+
result = min(int i | this.getNamedArg(i) instanceof DictUnpacking)
193202
}
194203

195204
/**

python/ql/lib/semmle/python/dataflow/new/internal/DataFlowPublic.qll

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,15 @@ class ModuleVariableNode extends Node, TModuleVariableNode {
401401
private predicate isAccessedThroughImportStar(Module m) { m = ImportStar::getStarImported(_) }
402402

403403
private ModuleVariableNode import_star_read(Node n) {
404-
ImportStar::importStarResolvesTo(n.asCfgNode(), result.getModule()) and
405-
n.asCfgNode().(NameNode).getId() = result.getVariable().getId()
404+
resolved_import_star_module(result.getModule(), result.getVariable().getId(), n)
405+
}
406+
407+
pragma[nomagic]
408+
private predicate resolved_import_star_module(Module m, string name, Node n) {
409+
exists(NameNode nn | nn = n.asCfgNode() |
410+
ImportStar::importStarResolvesTo(pragma[only_bind_into](nn), m) and
411+
nn.getId() = name
412+
)
406413
}
407414

408415
/**

python/ql/lib/semmle/python/pointsto/PointsTo.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2129,7 +2129,7 @@ module Conditionals {
21292129
/** INTERNAL: Do not use. */
21302130
predicate declaredAttributeVar(PythonClassObjectInternal cls, string name, EssaVariable var) {
21312131
name = var.getName() and
2132-
var.getAUse() = cls.getScope().getANormalExit()
2132+
pragma[only_bind_into](pragma[only_bind_into](var).getAUse()) = cls.getScope().getANormalExit()
21332133
}
21342134

21352135
cached

0 commit comments

Comments
 (0)