github / github/codeql

Python: Local/Global dataflow analysis not tracing class field?

Đang mở
#17,021 3 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ả

## Python
```python
class Cls:
def __init__(self) -> None:
self.field = 1
def __init__(self, num) -> None:
self.field = num
def print(self) -> None:
print(self.field)

if __name__ == '__main__':
var1 = Cls(2)
var2 = var1
var2.field = 3
var1.print()
var1.field2 = 4
print(var2.field2)

```
## CodeQL
```codeql
import python
import semmle.python.ApiGraphs
import semmle.python.dataflow.new.DataFlow
import semmle.python.dataflow.new.TaintTracking

module MyConf implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node source) {
source.asExpr() instanceof IntegerLiteral
}
predicate isSink(DataFlow::Node sink) {
sink = API::builtin("print").getACall().getArg(0)
}
}

module MyFlow = DataFlow::Global;

from DataFlow::Node source, DataFlow::Node sink
where MyFlow::flow(source, sink)
select source, sink
```
## Output
|source|sink|
|-|-|
|1|`self.field` in line 7|
|2|`self.field` in line 7|
## Expected result
|source|sink|
|-|-|
|1|`self.field` in line 7|
|2|`self.field` in line 7|
|3|`self.field` in line 7|
|4|`self.field` in line 16|

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

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

Đánh giá

Issue này chưa được đánh giá.

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.