Skip to content

Commit ee4190e

Browse files
committed
Python: Add example if urlsplit(url).path: => missing points-to
I wanted to highlight that it's not the call to `urlsplit` that is a problem, so that's why I inserted a `check` in-between.
1 parent 8dd19ca commit ee4190e

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-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

0 commit comments

Comments
 (0)