Skip to content

Commit 642f9dc

Browse files
Model missing builtins
1 parent 0957113 commit 642f9dc

File tree

1 file changed

+112
-0
lines changed

1 file changed

+112
-0
lines changed

python/ql/lib/semmle/python/frameworks/Stdlib.qll

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4523,6 +4523,118 @@ module StdlibPrivate {
45234523
}
45244524
}
45254525

4526+
/** A flow summary for `map`. */
4527+
class MapSummary extends SummarizedCallable {
4528+
MapSummary() { this = "builtins.map" }
4529+
4530+
override DataFlow::CallCfgNode getACall() { result = API::builtin("map").getACall() }
4531+
4532+
override DataFlow::ArgumentNode getACallback() {
4533+
result = API::builtin("map").getAValueReachableFromSource()
4534+
}
4535+
4536+
override predicate propagatesFlow(string input, string output, boolean preservesValue) {
4537+
exists(int i | exists(any(Call c).getArg(i)) |
4538+
(
4539+
input = "Argument[" + (i + 1).toString() + "].ListElement"
4540+
or
4541+
input = "Argument[" + (i + 1).toString() + "].SetElement"
4542+
or
4543+
exists(DataFlow::TupleElementContent tc, int j | j = tc.getIndex() |
4544+
input = "Argument[" + (i + 1).toString() + "].TupleElement[" + j.toString() + "]"
4545+
)
4546+
// TODO: Once we have DictKeyContent, we need to transform that into ListElementContent
4547+
) and
4548+
output = "Argument[0].Parameter[" + i.toString() + "]" and
4549+
preservesValue = true
4550+
)
4551+
or
4552+
input = "Argument[0].ReturnValue" and
4553+
output = "ReturnValue.ListElement" and
4554+
preservesValue = true
4555+
}
4556+
}
4557+
4558+
/** A flow summary for `filter`. */
4559+
class FilterSummary extends SummarizedCallable {
4560+
FilterSummary() { this = "builtins.filter" }
4561+
4562+
override DataFlow::CallCfgNode getACall() { result = API::builtin("filter").getACall() }
4563+
4564+
override DataFlow::ArgumentNode getACallback() {
4565+
result = API::builtin("filter").getAValueReachableFromSource()
4566+
}
4567+
4568+
override predicate propagatesFlow(string input, string output, boolean preservesValue) {
4569+
(
4570+
input = "Argument[1].ListElement"
4571+
or
4572+
input = "Argument[1].SetElement"
4573+
or
4574+
exists(DataFlow::TupleElementContent tc, int i | i = tc.getIndex() |
4575+
input = "Argument[1].TupleElement[" + i.toString() + "]"
4576+
)
4577+
// TODO: Once we have DictKeyContent, we need to transform that into ListElementContent
4578+
) and
4579+
output = "Argument[0].Parameter[0]" and
4580+
preservesValue = true
4581+
}
4582+
}
4583+
4584+
/**A summary for `enumerate`. */
4585+
class EnumerateSummary extends SummarizedCallable {
4586+
EnumerateSummary() { this = "builtins.enumerate" }
4587+
4588+
override DataFlow::CallCfgNode getACall() { result = API::builtin("enumerate").getACall() }
4589+
4590+
override DataFlow::ArgumentNode getACallback() {
4591+
result = API::builtin("enumerate").getAValueReachableFromSource()
4592+
}
4593+
4594+
override predicate propagatesFlow(string input, string output, boolean preservesValue) {
4595+
(
4596+
input = "Argument[0].ListElement"
4597+
or
4598+
input = "Argument[0].SetElement"
4599+
or
4600+
exists(DataFlow::TupleElementContent tc, int i | i = tc.getIndex() |
4601+
input = "Argument[0].TupleElement[" + i.toString() + "]"
4602+
)
4603+
// TODO: Once we have DictKeyContent, we need to transform that into ListElementContent
4604+
) and
4605+
output = "ReturnValue.ListElement.TupleElement[1]" and
4606+
preservesValue = true
4607+
}
4608+
}
4609+
4610+
/** A flow summary for ``zip`. */
4611+
class ZipSummary extends SummarizedCallable {
4612+
ZipSummary() { this = "builtins.zip" }
4613+
4614+
override DataFlow::CallCfgNode getACall() { result = API::builtin("zip").getACall() }
4615+
4616+
override DataFlow::ArgumentNode getACallback() {
4617+
result = API::builtin("zip").getAValueReachableFromSource()
4618+
}
4619+
4620+
override predicate propagatesFlow(string input, string output, boolean preservesValue) {
4621+
exists(int i | exists(any(Call c).getArg(i)) |
4622+
(
4623+
input = "Argument[" + i.toString() + "].ListElement"
4624+
or
4625+
input = "Argument[" + i.toString() + "].SetElement"
4626+
or
4627+
exists(DataFlow::TupleElementContent tc, int j | j = tc.getIndex() |
4628+
input = "Argument[" + i.toString() + "].TupleElement[" + j.toString() + "]"
4629+
)
4630+
// TODO: Once we have DictKeyContent, we need to transform that into ListElementContent
4631+
) and
4632+
output = "ReturnValue.ListElement.TupleElement[" + i.toString() + "]" and
4633+
preservesValue = true
4634+
)
4635+
}
4636+
}
4637+
45264638
// ---------------------------------------------------------------------------
45274639
// Flow summaries for container methods
45284640
// ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)