|
15 | 15 | import python |
16 | 16 | import semmle.python.strings |
17 | 17 |
|
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) |
22 | 23 | ) |
23 | 24 | } |
24 | 25 |
|
25 | | -int sequence_length(Object args) { |
| 26 | +int sequence_length(Value args) { |
26 | 27 | /* Guess length of sequence */ |
27 | | - exists(Tuple seq | |
28 | | - seq = args.getOrigin() | |
| 28 | + exists(Tuple seq, AstNode origin | |
| 29 | + seq.pointsTo(args,origin) | |
29 | 30 | result = strictcount(seq.getAnElt()) and |
30 | 31 | not seq.getAnElt() instanceof Starred |
31 | 32 | ) |
32 | 33 | or |
33 | 34 | exists(ImmutableLiteral i | |
34 | | - i.getLiteralObject() = args | |
| 35 | + i.getLiteralValue() = args | |
35 | 36 | result = 1 |
36 | 37 | ) |
37 | 38 | } |
38 | 39 |
|
39 | 40 |
|
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 |
41 | 42 | where string_format(operation, fmt, args, origin) and slen = sequence_length(args) and alen = format_items(fmt) and slen != alen and |
42 | 43 | (if slen = 1 then provided = " is provided." else provided = " are provided.") |
43 | 44 | select operation, "Wrong number of $@ for string format. Format $@ takes " + alen.toString() + ", but " + slen.toString() + provided, |
|
0 commit comments