Skip to content

Commit 67647bd

Browse files
committed
Python: Fix false positive for py/use-of-input.
Fixes #1969. The points-to analysis does not know that the assignment `input = raw_input` cannot fail under Python 2, and so there are two possible values that `input` could point-to after exiting the exception handler: the built-in `input`, or the built-in `raw_input`. In the latter case we do not want to report the alert, and so adding a check that the given function does not point-to the built-in `raw_input` suffices.
1 parent 77c869f commit 67647bd

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

python/ql/src/Expressions/UseofInput.ql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,8 @@ import python
1414

1515
from CallNode call, Context context, ControlFlowNode func
1616
where
17-
context.getAVersion().includes(2, _) and call.getFunction() = func and func.refersTo(context, Object::builtin("input"), _, _)
17+
context.getAVersion().includes(2, _) and
18+
call.getFunction() = func and
19+
func.pointsTo(context, Value::named("input"), _) and
20+
not func.pointsTo(context, Value::named("raw_input"), _)
1821
select call, "The unsafe built-in function 'input' is used."
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
try:
2+
input = raw_input
3+
except NameError:
4+
pass
5+
6+
def use_of_input():
7+
return input()
8+
9+
print(use_of_input())
10+

0 commit comments

Comments
 (0)