Skip to content

Commit 2632422

Browse files
committed
Python: Add FP test for unknown argument in string format
Reported in github#2650 I found this during a bit of spring cleaning in my working directory. As this doesn't have any immediate security implications, I don't know when we'll get round to fixing it, but it can't hurt to have the test case checked in.
1 parent 179a7a8 commit 2632422

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

python/ql/test/query-tests/Expressions/Formatting/UnusedNamedArgumentIn3101Format.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@
66
| test.py:45:1:45:35 | format() | Surplus named argument for string format. An argument named 'z' is provided, but it is not required by $@. | test.py:39:14:39:18 | Str | any format used. |
77
| test.py:46:1:46:34 | Attribute() | Surplus named argument for string format. An argument named 'z' is provided, but it is not required by $@. | test.py:37:14:37:18 | Str | any format used. |
88
| test.py:46:1:46:34 | Attribute() | Surplus named argument for string format. An argument named 'z' is provided, but it is not required by $@. | test.py:39:14:39:18 | Str | any format used. |
9+
| unknown_format_string.py:9:12:9:30 | Attribute() | Surplus named argument for string format. An argument named 'b' is provided, but it is not required by $@. | unknown_format_string.py:8:15:8:19 | Str | format "{a}" |
10+
| unknown_format_string.py:17:12:17:30 | Attribute() | Surplus named argument for string format. An argument named 'b' is provided, but it is not required by $@. | unknown_format_string.py:16:15:16:19 | Str | format "{a}" |
11+
| unknown_format_string.py:25:12:25:30 | Attribute() | Surplus named argument for string format. An argument named 'b' is provided, but it is not required by $@. | unknown_format_string.py:24:15:24:19 | Str | format "{a}" |
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# FP Reported in https://github.com/github/codeql/issues/2650
2+
3+
def possibly_unknown_format_string1(x):
4+
user_specified = unknown_function()
5+
if user_specified:
6+
fmt = user_specified
7+
else:
8+
fmt = "{a}"
9+
return fmt.format(a=1,b=2)
10+
11+
def possibly_unknown_format_string2(x):
12+
user_specified = input()
13+
if user_specified:
14+
fmt = user_specified
15+
else:
16+
fmt = "{a}"
17+
return fmt.format(a=1,b=2)
18+
19+
20+
def possibly_unknown_format_string3(x):
21+
if unknown_function():
22+
fmt = input()
23+
else:
24+
fmt = "{a}"
25+
return fmt.format(a=1,b=2)

0 commit comments

Comments
 (0)