Skip to content

Commit a04ed8f

Browse files
committed
Python: Port FromImportOfMutableAttribute.ql
A fairly straightforward port. No test changes.
1 parent fdfee9d commit a04ed8f

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

python/ql/src/Imports/FromImportOfMutableAttribute.ql

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,26 @@
1212
*/
1313

1414
import python
15-
private import LegacyPointsTo
15+
import semmle.python.dataflow.new.DataFlow
16+
private import semmle.python.dataflow.new.internal.ImportResolution
1617
import semmle.python.filters.Tests
1718

18-
from ImportMember im, ModuleValue m, AttrNode store_attr, string name
19+
from ImportMember im, Module m, DataFlow::AttrWrite store_attr, string name
1920
where
20-
m.importedAs(im.getModule().(ImportExpr).getImportedModuleName()) and
21+
ImportResolution::getImmediateModuleReference(m).asExpr() = im.getModule() and
2122
im.getName() = name and
2223
/* Modification must be in a function, so it can occur during lifetime of the import value */
23-
store_attr.getScope() instanceof Function and
24+
store_attr.getObject().getScope() instanceof Function and
2425
/* variable resulting from import must have a long lifetime */
2526
not im.getScope() instanceof Function and
26-
store_attr.isStore() and
27-
store_attr.getObject(name).(ControlFlowNodeWithPointsTo).pointsTo(m) and
27+
store_attr.getAttributeName() = name and
28+
ImportResolution::getModuleReference(m) = store_attr.getObject() and
2829
/* Import not in same module as modification. */
29-
not im.getEnclosingModule() = store_attr.getScope().getEnclosingModule() and
30+
not im.getEnclosingModule() = store_attr.getObject().getScope().getEnclosingModule() and
3031
/* Modification is not in a test */
31-
not store_attr.getScope().getScope*() instanceof TestScope
32+
not store_attr.getObject().getScope().getScope*() instanceof TestScope
3233
select im,
3334
"Importing the value of '" + name +
3435
"' from $@ means that any change made to $@ will be not be observed locally.", m,
35-
"module " + m.getName(), store_attr, m.getName() + "." + store_attr.getName()
36+
"module " + ImportResolution::moduleName(m), store_attr,
37+
ImportResolution::moduleName(m) + "." + store_attr.getAttributeName()

0 commit comments

Comments
 (0)