Skip to content

Commit 5902da4

Browse files
committed
Python: recover taint for % format strings
1 parent e9bc435 commit 5902da4

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,10 +1018,21 @@ module Conversions {
10181018
)
10191019
}
10201020

1021+
predicate formatReadStep(Node nodeFrom, ContentSet c, Node nodeTo) {
1022+
// % formatting
1023+
exists(BinaryExprNode fmt | fmt = nodeTo.asCfgNode() |
1024+
fmt.getOp() instanceof Mod and
1025+
fmt.getRight() = nodeFrom.asCfgNode()
1026+
) and
1027+
c instanceof TupleElementContent
1028+
}
1029+
10211030
predicate readStep(Node nodeFrom, ContentSet c, Node nodeTo) {
10221031
decoderReadStep(nodeFrom, c, nodeTo)
10231032
or
10241033
encoderReadStep(nodeFrom, c, nodeTo)
1034+
or
1035+
formatReadStep(nodeFrom, c, nodeTo)
10251036
}
10261037
}
10271038

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)