awslabs / awslabs/aws-crt-python
Seg fault after running awscrt.io.init_logging with invalid parameters
- Dominant language
- Python
- Stars
- 100
- Forks
- 58
- Avg merge
- 13h 51m
- Merged PRs (30d)
- 2
Description
### Describe the bug
Running `awscrt.io.init_logging(False, False)` the first time correctly throws a python exception.
Running it a second time results in a seg fault.
A seg fault occurs even if in the second time the parameters are valid (like `awscrt.io.init_logging(1, "/dev/null")`)
I think (I am not sure) this is because when passing in invalid parameters, it sets `s_logger_init = true;` but does not actually create the logger (due to invalid parameters), and the second time it tries to cleanup the previous non-existent logger and therefore fails.
https://github.com/awslabs/aws-crt-python/blob/e6a48db2b9c16288af5ae0b8bd5269eb9d3c3c02/source/module.c#L39-L60
### Regression Issue
- [ ] Select this option if this issue appears to be a regression.
### Expected Behavior
It does not produce a seg fault. At worst it fails with a python exception.
### Current Behavior
It produces a seg fault.
### Reproduction Steps
Run the following:
```python
import awscrt.io
try:
awscrt.io.init_logging(False, False)
except ValueError:
pass
awscrt.io.init_logging(False, False)
```
Output looks like:
```
Fatal Python error: Segmentation fault
Current thread 0x00007f4afd2837c0 (most recent call first):
File "/home/user/.local/lib/python3.13/site-packages/awscrt/io.py", line 40 in init_logging
File "/tmp/test.py", line 6 in
Extension modules: _awscrt (total: 1)
[1] 1876122 segmentation fault (core dumped) python3 /tmp/test.py
```
### Possible Solution
_No response_
### Additional Information/Context
_No response_
### aws-crt-python version used
0.27.6
### Python version used
3.13.7
### Operating System and version
Linux fedora 6.15.10-200.fc42.x86_64
Contributor guide
Assessment
This issue has not been assessed yet.