github / github/codeql

Python: Call analysis fails in some scenarios

Offen
#19,288 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
question
Vorherrschende Sprache
CodeQL
Sterne
10.1k
Forks
2.1k
Ø Merge
2 T. 15 Std.
Gemergte PRs (30 T.)
141

Beschreibung

While trying to use the 'pointsTo' approach for some basic control-flow-based queries (please let me know if there's a better approach to find 'all statements reachable from a function entry-point'), I've noticed that currently, some calls are incorrectly picked up without any value to point to.

MWE:
```python
import sys

def mwe_callable():
print("Hello, World!") # works

def mwe_broken():
if herp := sys.argv[1]:
raise Exception("merp") # broken

mwe_callable() # broken

def mwe_broken2():
if herp := "derp":
print("merp") # broken

mwe_callable() # works

def mwe_works():
if sys.argv[1] == "derp":
raise Exception("merp") # works

mwe_callable() # works

def mwe_works2():
print("merp") # works
mwe_callable() # works
```

Test query:
```codeql
import python

from Function f, Call c, Expr e
where
f.contains(c) and
e = c.getFunc() and
not exists(Value v | e.pointsTo() = v)
select f, c, e
```

Every call I've marked here as 'broken' is returned by the query as not having any Value to point to, whereas the other calls are correctly identified and associated with their target.

I am using:
- CodeQL CLI 2.21.0
- CodeQL VSCode extension 1.17.2
- codeql/python-all@4.0.4
- Python extractor 1.22.1

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Start by running the supplied CodeQL query against the minimal Python example and compare the calls marked as working or broken. Review the Python extractor and pointsTo behavior for assignment expressions and confirm that the query no longer reports calls whose targets have a Value.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
devtools
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.