Skip to content

Commit 72c6919

Browse files
authored
Merge pull request github#13095 from yoff/python/interpret-summary-content
Python: Interpret summary content
2 parents 8e18627 + 9bd3957 commit 72c6919

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

python/ql/lib/semmle/python/dataflow/new/FlowSummary.qll

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,27 @@ module SummaryComponent {
2828
/** Gets a summary component that represents a list element. */
2929
SummaryComponent listElement() { result = content(any(ListElementContent c)) }
3030

31+
/** Gets a summary component that represents a set element. */
32+
SummaryComponent setElement() { result = content(any(SetElementContent c)) }
33+
34+
/** Gets a summary component that represents a tuple element. */
35+
SummaryComponent tupleElement(int index) {
36+
exists(TupleElementContent c | c.getIndex() = index and result = content(c))
37+
}
38+
39+
/** Gets a summary component that represents a dictionary element. */
40+
SummaryComponent dictionaryElement(string key) {
41+
exists(DictionaryElementContent c | c.getKey() = key and result = content(c))
42+
}
43+
44+
/** Gets a summary component that represents a dictionary element at any key. */
45+
SummaryComponent dictionaryElementAny() { result = content(any(DictionaryElementAnyContent c)) }
46+
47+
/** Gets a summary component that represents an attribute element. */
48+
SummaryComponent attribute(string attr) {
49+
exists(AttributeContent c | c.getAttribute() = attr and result = content(c))
50+
}
51+
3152
/** Gets a summary component that represents the return value of a call. */
3253
SummaryComponent return() { result = SC::return(any(ReturnKind rk)) }
3354
}

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,27 @@ predicate neutralSummaryElement(FlowSummary::SummarizedCallable c, string proven
105105
SummaryComponent interpretComponentSpecific(AccessPathToken c) {
106106
c = "ListElement" and
107107
result = FlowSummary::SummaryComponent::listElement()
108+
or
109+
c = "SetElement" and
110+
result = FlowSummary::SummaryComponent::setElement()
111+
or
112+
exists(int index |
113+
c.getAnArgument("TupleElement") = index.toString() and
114+
result = FlowSummary::SummaryComponent::tupleElement(index)
115+
)
116+
or
117+
exists(string key |
118+
c.getAnArgument("DictionaryElement") = key and
119+
result = FlowSummary::SummaryComponent::dictionaryElement(key)
120+
)
121+
or
122+
c = "DictionaryElementAny" and
123+
result = FlowSummary::SummaryComponent::dictionaryElementAny()
124+
or
125+
exists(string attr |
126+
c.getAnArgument("Attribute") = attr and
127+
result = FlowSummary::SummaryComponent::attribute(attr)
128+
)
108129
}
109130

110131
/** Gets the textual representation of a summary component in the format used for flow summaries. */

0 commit comments

Comments
 (0)