github / github/codeql

Python: Call analysis fails in some scenarios

Đang mở
#19,288 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
question
Ngôn ngữ chính
CodeQL
Star
10.1k
Fork
2.1k
Merge trung bình
2 ngày 15 giờ
Pull request đã merge (30 ngày)
141

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Bắt đầu bằng cách chạy truy vấn CodeQL được cung cấp trên ví dụ Python tối thiểu và so sánh các lệnh gọi được đánh dấu là hoạt động hoặc bị lỗi. Xem lại extractor Python và hành vi của pointsTo đối với các biểu thức gán, đồng thời xác nhận rằng truy vấn không còn báo cáo các lệnh gọi có đích chứa một Value.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
devtools
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.