Skip to content

Commit 54d1991

Browse files
authored
Merge pull request github#3300 from RasmusWL/python-pointsto-regression-open
Python: Add points-to regression for uncalled function
2 parents adf12ba + 1631787 commit 54d1991

File tree

5 files changed

+40
-10
lines changed

5 files changed

+40
-10
lines changed
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import python
22

3-
from NameNode name, CallNode call, string debug
3+
from ControlFlowNode arg, CallNode call, string debug
44
where
5-
call.getAnArg() = name and
5+
call.getAnArg() = arg and
66
call.getFunction().(NameNode).getId() = "check" and
7-
if exists(name.pointsTo())
8-
then debug = name.pointsTo().toString()
7+
if exists(arg.pointsTo())
8+
then debug = arg.pointsTo().toString()
99
else debug = "<MISSING pointsTo()>"
10-
select name, debug
10+
select arg, debug
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import python
22

3-
from NameNode name, CallNode call, string debug
3+
from ControlFlowNode arg, CallNode call, string debug
44
where
5-
call.getAnArg() = name and
5+
call.getAnArg() = arg and
66
call.getFunction().(NameNode).getId() = "check" and
7-
if exists(name.pointsTo())
8-
then debug = name.pointsTo().toString()
7+
if exists(arg.pointsTo())
8+
then debug = arg.pointsTo().toString()
99
else debug = "<MISSING pointsTo()>"
10-
select name, debug
10+
select arg, debug
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| test.py:10:11:10:14 | ControlFlowNode for open | <MISSING pointsTo()> |
2+
| test.py:14:11:14:14 | ControlFlowNode for open | Builtin-function open |
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import python
2+
3+
from ControlFlowNode arg, CallNode call, string debug
4+
where
5+
call.getAnArg() = arg and
6+
call.getFunction().(NameNode).getId() = "check" and
7+
if exists(arg.pointsTo())
8+
then debug = arg.pointsTo().toString()
9+
else debug = "<MISSING pointsTo()>"
10+
select arg, debug
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Points-to information seems to be missing if our analysis thinks the enclosing function
2+
# is never called. However, as illustrated by the code below, it's easy to fool our
3+
# analysis :(
4+
5+
# This was inspired by a problem in real code, where our analysis doesn't have any
6+
# points-to information about the `open` call in
7+
# https://google-gruyere.appspot.com/code/gruyere.py on line 227
8+
9+
def _func_not_called(filename, mode='rb'):
10+
check(open)
11+
return open(filename, mode)
12+
13+
def _func_called(filename, mode='rb'):
14+
check(open)
15+
return open(filename, mode)
16+
17+
globals()['_func_not_called']('test.txt')
18+
_func_called('test.txt')

0 commit comments

Comments
 (0)