Skip to content

Commit 4c1d76e

Browse files
authored
Merge pull request github#2937 from BekaValentine/python-objectapi-to-valueapi-wrongnumberargumentsforformat
Approved by tausbn
2 parents c690e25 + ce204ac commit 4c1d76e

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

python/ql/src/Expressions/WrongNumberArgumentsForFormat.ql

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,30 @@
1515
import python
1616
import semmle.python.strings
1717

18-
predicate string_format(BinaryExpr operation, StrConst str, Object args, AstNode origin) {
19-
exists(Object fmt, Context ctx | operation.getOp() instanceof Mod |
20-
operation.getLeft().refersTo(ctx, fmt, _, str) and
21-
operation.getRight().refersTo(ctx, args, _, origin)
18+
predicate string_format(BinaryExpr operation, StrConst str, Value args, AstNode origin) {
19+
operation.getOp() instanceof Mod and
20+
exists(Value fmt, Context ctx |
21+
operation.getLeft().pointsTo(ctx, fmt, str) and
22+
operation.getRight().pointsTo(ctx, args, origin)
2223
)
2324
}
2425

25-
int sequence_length(Object args) {
26+
int sequence_length(Value args) {
2627
/* Guess length of sequence */
27-
exists(Tuple seq |
28-
seq = args.getOrigin() |
28+
exists(Tuple seq, AstNode origin |
29+
seq.pointsTo(args,origin) |
2930
result = strictcount(seq.getAnElt()) and
3031
not seq.getAnElt() instanceof Starred
3132
)
3233
or
3334
exists(ImmutableLiteral i |
34-
i.getLiteralObject() = args |
35+
i.getLiteralValue() = args |
3536
result = 1
3637
)
3738
}
3839

3940

40-
from BinaryExpr operation, StrConst fmt, Object args, int slen, int alen, AstNode origin, string provided
41+
from BinaryExpr operation, StrConst fmt, Value args, int slen, int alen, AstNode origin, string provided
4142
where string_format(operation, fmt, args, origin) and slen = sequence_length(args) and alen = format_items(fmt) and slen != alen and
4243
(if slen = 1 then provided = " is provided." else provided = " are provided.")
4344
select operation, "Wrong number of $@ for string format. Format $@ takes " + alen.toString() + ", but " + slen.toString() + provided,

0 commit comments

Comments
 (0)