Skip to content

Seg fault after running awscrt.io.init_logging with invalid parameters #685

@lincheney

Description

@lincheney

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.

PyObject *aws_py_init_logging(PyObject *self, PyObject *args) {
(void)self;
if (s_logger_init) {
aws_logger_set(NULL);
aws_logger_clean_up(&s_logger);
}
s_logger_init = true;
/* NOTE: We are NOT using aws_py_get_allocator() for logging.
* This avoid deadlock during aws_mem_tracer_dump() */
struct aws_allocator *allocator = aws_default_allocator();
int log_level = 0;
const char *file_path = NULL;
Py_ssize_t file_path_len = 0;
if (!PyArg_ParseTuple(args, "bs#", &log_level, &file_path, &file_path_len)) {
PyErr_SetNone(PyExc_ValueError);
return NULL;
}

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:

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 <module>

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions