Skip to content

Commit e3160f9

Browse files
authored
Merge pull request github#2932 from RasmusWL/python-re.compile-missing-points-to
Python: Add example of re.compile missing points-to
2 parents 28a9bab + ee4190e commit e3160f9

File tree

7 files changed

+47
-0
lines changed

7 files changed

+47
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
| test.py:5:7:5:9 | ControlFlowNode for foo | int 42 |
2+
| test.py:11:11:11:13 | ControlFlowNode for foo | int 1 |
3+
| test.py:17:11:17:13 | ControlFlowNode for foo | <MISSING pointsTo()> |
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import python
2+
3+
from NameNode name, CallNode call, string debug
4+
where
5+
call.getAnArg() = name and
6+
call.getFunction().(NameNode).getId() = "check" and
7+
if exists(name.pointsTo())
8+
then debug = name.pointsTo().toString()
9+
else debug = "<MISSING pointsTo()>"
10+
select name, debug
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
semmle-extractor-options: --max-import-depth=1 --lang=3
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Only a problem in Python 3
2+
from urllib.parse import urlsplit
3+
4+
foo = 42
5+
check(foo)
6+
7+
def func(url):
8+
parts = urlsplit(url)
9+
10+
foo = 1
11+
check(foo)
12+
13+
if parts.path: # using `urlsplit(url).path` here is equivalent
14+
return # using `pass` here instead makes points-to work
15+
16+
foo = 2
17+
check(foo) # no points-to information
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| test.py:5:7:5:13 | ControlFlowNode for PATTERN | <MISSING pointsTo()> |
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import python
2+
3+
from NameNode name, CallNode call, string debug
4+
where
5+
call.getAnArg() = name and
6+
call.getFunction().(NameNode).getId() = "check" and
7+
if exists(name.pointsTo())
8+
then debug = name.pointsTo().toString()
9+
else debug = "<MISSING pointsTo()>"
10+
select name, debug
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import re
2+
3+
PATTERN = re.compile("a|b")
4+
5+
check(PATTERN)

0 commit comments

Comments
 (0)