Skip to content

Commit 1c91b92

Browse files
authored
Merge pull request #1482 from markshannon/python-fix-odasa-7104
Backport #1407 to rc/1.21
2 parents 8b58b80 + bbf25f3 commit 1c91b92

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -726,10 +726,12 @@ private module InterModulePointsTo {
726726
|
727727
src.declaredInAll(name) and result = true
728728
or
729-
src.declaredInAll(_) and not src.declaredInAll(name) and
729+
declared_all_is_simple(src) and
730+
not src.declaredInAll(name) and
730731
ofInterestInExports(mod, name) and result = false
731732
or
732-
not src.declaredInAll(_) and
733+
(not src.declaredInAll(name) and not declared_all_is_simple(src))
734+
and
733735
exists(ObjectInternal val |
734736
ModuleAttributes::pointsToAtExit(src, name, val, _) |
735737
val = ObjectInternal::undefined() and result = false
@@ -739,6 +741,17 @@ private module InterModulePointsTo {
739741
)
740742
}
741743

744+
/** Holds if __all__ is declared and not mutated */
745+
private predicate declared_all_is_simple(Module m) {
746+
exists(AssignStmt a, GlobalVariable all |
747+
a.defines(all) and a.getScope() = m and
748+
all.getId() = "__all__" and
749+
not exists(Attribute attr |
750+
all.getALoad() = attr.getObject()
751+
)
752+
)
753+
}
754+
742755
private boolean packageExportsBoolean(PackageObjectInternal mod, string name) {
743756
exists(Folder folder |
744757
folder = mod.getFolder() |

python/ql/test/library-tests/PointsTo/imports/Runtime.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,6 @@
5252
| test.py | 24 | ControlFlowNode for argv | int 0 | ControlFlowNode for IntegerLiteral |
5353
| test.py | 27 | ControlFlowNode for ImportExpr | Module sys | ControlFlowNode for ImportExpr |
5454
| test.py | 31 | ControlFlowNode for argv | list object | ControlFlowNode for from sys import * |
55+
| test.py | 33 | ControlFlowNode for ImportExpr | Module socket | ControlFlowNode for ImportExpr |
56+
| test.py | 34 | ControlFlowNode for timeout | builtin-class socket.timeout | ControlFlowNode for from _socket import * |
5557
| x.py | 2 | ControlFlowNode for ImportExpr | Module sys | ControlFlowNode for ImportExpr |

python/ql/test/library-tests/PointsTo/imports/RuntimeWithType.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,6 @@
5252
| test.py | 24 | ControlFlowNode for argv | int 0 | builtin-class int | ControlFlowNode for IntegerLiteral |
5353
| test.py | 27 | ControlFlowNode for ImportExpr | Module sys | builtin-class module | ControlFlowNode for ImportExpr |
5454
| test.py | 31 | ControlFlowNode for argv | list object | builtin-class list | ControlFlowNode for from sys import * |
55+
| test.py | 33 | ControlFlowNode for ImportExpr | Module socket | builtin-class module | ControlFlowNode for ImportExpr |
56+
| test.py | 34 | ControlFlowNode for timeout | builtin-class socket.timeout | builtin-class type | ControlFlowNode for from _socket import * |
5557
| x.py | 2 | ControlFlowNode for ImportExpr | Module sys | builtin-class module | ControlFlowNode for ImportExpr |

python/ql/test/library-tests/PointsTo/imports/test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@ def f(self):
2929
pass
3030

3131
argv
32+
33+
from socket import *
34+
timeout

0 commit comments

Comments
 (0)