Python: Call analysis fails in some scenarios
- Lingua principale
- CodeQL
- Stelle
- 10.1k
- Fork
- 2.1k
- Merge medio
- 2g 15h
- PR unite (30g)
- 141
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Inizia eseguendo la query CodeQL fornita sull'esempio Python minimo e confronta le chiamate contrassegnate come funzionanti o non funzionanti. Esamina l'estrattore Python e il comportamento di pointsTo per le espressioni di assegnazione e conferma che la query non segnali più le chiamate i cui target hanno un Value.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- devtools
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100