Skip to content

Commit 1ff67f7

Browse files
authored
Merge pull request #1407 from markshannon/python-fix-odasa-7104
Python points-to. Improve handling of socket module.
2 parents 6c9d68d + 75f87bb commit 1ff67f7

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
@@ -717,10 +717,12 @@ private module InterModulePointsTo {
717717
|
718718
src.declaredInAll(name) and result = true
719719
or
720-
src.declaredInAll(_) and not src.declaredInAll(name) and
720+
declared_all_is_simple(src) and
721+
not src.declaredInAll(name) and
721722
ofInterestInExports(mod, name) and result = false
722723
or
723-
not src.declaredInAll(_) and
724+
(not src.declaredInAll(name) and not declared_all_is_simple(src))
725+
and
724726
exists(ObjectInternal val |
725727
ModuleAttributes::pointsToAtExit(src, name, val, _) |
726728
val = ObjectInternal::undefined() and result = false
@@ -730,6 +732,17 @@ private module InterModulePointsTo {
730732
)
731733
}
732734

735+
/** Holds if __all__ is declared and not mutated */
736+
private predicate declared_all_is_simple(Module m) {
737+
exists(AssignStmt a, GlobalVariable all |
738+
a.defines(all) and a.getScope() = m and
739+
all.getId() = "__all__" and
740+
not exists(Attribute attr |
741+
all.getALoad() = attr.getObject()
742+
)
743+
)
744+
}
745+
733746
private boolean packageExportsBoolean(PackageObjectInternal mod, string name) {
734747
exists(Folder folder |
735748
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)