mirror of
https://github.com/github/codeql.git
synced 2025-12-20 18:56:32 +01:00
Merge pull request #2932 from RasmusWL/python-re.compile-missing-points-to
Python: Add example of re.compile missing points-to
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
| test.py:5:7:5:9 | ControlFlowNode for foo | int 42 |
|
||||
| test.py:11:11:11:13 | ControlFlowNode for foo | int 1 |
|
||||
| test.py:17:11:17:13 | ControlFlowNode for foo | <MISSING pointsTo()> |
|
||||
@@ -0,0 +1,10 @@
|
||||
import python
|
||||
|
||||
from NameNode name, CallNode call, string debug
|
||||
where
|
||||
call.getAnArg() = name and
|
||||
call.getFunction().(NameNode).getId() = "check" and
|
||||
if exists(name.pointsTo())
|
||||
then debug = name.pointsTo().toString()
|
||||
else debug = "<MISSING pointsTo()>"
|
||||
select name, debug
|
||||
@@ -0,0 +1 @@
|
||||
semmle-extractor-options: --max-import-depth=1 --lang=3
|
||||
@@ -0,0 +1,17 @@
|
||||
# Only a problem in Python 3
|
||||
from urllib.parse import urlsplit
|
||||
|
||||
foo = 42
|
||||
check(foo)
|
||||
|
||||
def func(url):
|
||||
parts = urlsplit(url)
|
||||
|
||||
foo = 1
|
||||
check(foo)
|
||||
|
||||
if parts.path: # using `urlsplit(url).path` here is equivalent
|
||||
return # using `pass` here instead makes points-to work
|
||||
|
||||
foo = 2
|
||||
check(foo) # no points-to information
|
||||
@@ -0,0 +1 @@
|
||||
| test.py:5:7:5:13 | ControlFlowNode for PATTERN | <MISSING pointsTo()> |
|
||||
@@ -0,0 +1,10 @@
|
||||
import python
|
||||
|
||||
from NameNode name, CallNode call, string debug
|
||||
where
|
||||
call.getAnArg() = name and
|
||||
call.getFunction().(NameNode).getId() = "check" and
|
||||
if exists(name.pointsTo())
|
||||
then debug = name.pointsTo().toString()
|
||||
else debug = "<MISSING pointsTo()>"
|
||||
select name, debug
|
||||
@@ -0,0 +1,5 @@
|
||||
import re
|
||||
|
||||
PATTERN = re.compile("a|b")
|
||||
|
||||
check(PATTERN)
|
||||
Reference in New Issue
Block a user