Skip to content

Commit 5774459

Browse files
committed
Python: restrict AttrRead with AttrNode.isLoad()
1 parent fb6b8eb commit 5774459

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ abstract class AttrRead extends AttrRef, Node, LocalSourceNode { }
204204
private class AttributeReadAsAttrRead extends AttrRead, CfgNode {
205205
override AttrNode node;
206206

207+
AttributeReadAsAttrRead() { node.isLoad() }
208+
207209
override Node getObject() { result.asCfgNode() = node.getObject() }
208210

209211
override ExprNode getAttributeNameExpr() {
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
| test.py:6:9:6:16 | ControlFlowNode for Attribute | test.py:6:9:6:12 | ControlFlowNode for self | foo |
2-
| test.py:9:1:9:9 | ControlFlowNode for Attribute | test.py:9:1:9:5 | ControlFlowNode for myobj | foo |
31
| test.py:10:1:10:9 | ControlFlowNode for Attribute | test.py:10:1:10:5 | ControlFlowNode for myobj | foo |
42
| test.py:13:1:13:21 | ControlFlowNode for getattr() | test.py:13:9:13:13 | ControlFlowNode for myobj | foo |

python/ql/test/experimental/dataflow/typetracking/attribute_tests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ def expects_string(x): # $ str=field SPURIOUS: int=field
2525

2626
def test_incompatible_types():
2727
x = SomeClass() # $int,str=field
28-
x.field = int(5) # $int=field int SPURIOUS: str=field str
28+
x.field = int(5) # $int=field int SPURIOUS: str=field
2929
expects_int(x) # $int=field SPURIOUS: str=field
30-
x.field = str("Hello") # $str=field str SPURIOUS: int=field int
30+
x.field = str("Hello") # $str=field str SPURIOUS: int=field
3131
expects_string(x) # $ str=field SPURIOUS: int=field
3232

3333
# set in different function

0 commit comments

Comments
 (0)