Python: recover taint for % format strings

This commit is contained in:
Rasmus Lerchedahl Petersen
2024-09-17 23:04:19 +02:00
committed by Owen Mansel-Chan
parent b67694b2ab
commit facb3b681d
2 changed files with 12 additions and 1 deletions

View File

@@ -1093,10 +1093,21 @@ module Conversions {
)
}
predicate formatReadStep(Node nodeFrom, ContentSet c, Node nodeTo) {
// % formatting
exists(BinaryExprNode fmt | fmt = nodeTo.asCfgNode() |
fmt.getOp() instanceof Mod and
fmt.getRight() = nodeFrom.asCfgNode()
) and
c instanceof TupleElementContent
}
predicate readStep(Node nodeFrom, ContentSet c, Node nodeTo) {
decoderReadStep(nodeFrom, c, nodeTo)
or
encoderReadStep(nodeFrom, c, nodeTo)
or
formatReadStep(nodeFrom, c, nodeTo)
}
}

View File

@@ -115,7 +115,7 @@ def percent_fmt():
ensure_tainted(
tainted_fmt % (1, 2), # $ tainted
"%s foo bar" % ts, # $ tainted
"%s %s %s" % (1, 2, ts), # $ MISSING: tainted
"%s %s %s" % (1, 2, ts), # $ tainted
)