Skip to content

Commit facb3b6

Browse files
yoffowen-mc
authored andcommitted
Python: recover taint for % format strings
1 parent b67694b commit facb3b6

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,10 +1093,21 @@ module Conversions {
10931093
)
10941094
}
10951095

1096+
predicate formatReadStep(Node nodeFrom, ContentSet c, Node nodeTo) {
1097+
// % formatting
1098+
exists(BinaryExprNode fmt | fmt = nodeTo.asCfgNode() |
1099+
fmt.getOp() instanceof Mod and
1100+
fmt.getRight() = nodeFrom.asCfgNode()
1101+
) and
1102+
c instanceof TupleElementContent
1103+
}
1104+
10961105
predicate readStep(Node nodeFrom, ContentSet c, Node nodeTo) {
10971106
decoderReadStep(nodeFrom, c, nodeTo)
10981107
or
10991108
encoderReadStep(nodeFrom, c, nodeTo)
1109+
or
1110+
formatReadStep(nodeFrom, c, nodeTo)
11001111
}
11011112
}
11021113

python/ql/test/library-tests/dataflow/tainttracking/defaultAdditionalTaintStep/test_string.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def percent_fmt():
115115
ensure_tainted(
116116
tainted_fmt % (1, 2), # $ tainted
117117
"%s foo bar" % ts, # $ tainted
118-
"%s %s %s" % (1, 2, ts), # $ MISSING: tainted
118+
"%s %s %s" % (1, 2, ts), # $ tainted
119119
)
120120

121121

0 commit comments

Comments
 (0)