Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e9ecc00

Browse files
committed
Python: Implement and use mayHaveAttributeName
1 parent b905a3d commit e9ecc00

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

python/ql/src/experimental/dataflow/TypeTracker.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ predicate returnStep(ReturnNode nodeFrom, Node nodeTo) {
116116
*/
117117
predicate basicStoreStep(Node nodeFrom, Node nodeTo, string attr) {
118118
exists(AttrWrite a |
119-
a.getAttributeName() = attr and
119+
a.mayHaveAttributeName(attr) and
120120
nodeFrom = a.getValue() and
121121
simpleLocalFlowStep*(nodeTo, a.getObject())
122122
)
@@ -127,7 +127,7 @@ predicate basicStoreStep(Node nodeFrom, Node nodeTo, string attr) {
127127
*/
128128
predicate basicLoadStep(Node nodeFrom, Node nodeTo, string attr) {
129129
exists(AttrRead a |
130-
attr = a.getAttributeName() and
130+
a.mayHaveAttributeName(attr) and
131131
nodeFrom = a.getObject() and
132132
nodeTo = a
133133
)

python/ql/src/experimental/dataflow/internal/Attributes.qll

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/** This module provides an API for attribute reads and writes. */
22

3+
import DataFlowUtil
34
import DataFlowPublic
45
private import DataFlowPrivate
56

@@ -22,7 +23,14 @@ abstract class AttrRef extends Node {
2223
abstract ExprNode getAttributeNameExpr();
2324

2425
/** Holds if this attribute reference may access an attribute named `attrName`. */
25-
predicate mayHaveAttributeName(string attrName) { none() }
26+
predicate mayHaveAttributeName(string attrName) {
27+
attrName = this.getAttributeName()
28+
or
29+
exists(Node nodeFrom |
30+
localFlow(nodeFrom, this.getAttributeNameExpr()) and
31+
attrName = nodeFrom.asExpr().(StrConst).getText()
32+
)
33+
}
2634

2735
/** Gets the name of the attribute being read or written, if it can be determined statically. */
2836
abstract string getAttributeName();

0 commit comments

Comments
 (0)