Open
Description
Bug report
Bug description:
Hi!
I'm working on a project that requires the embedded Python interpreter. When testing my project with the clang memory sanitizer, I've caught the bug in the Py_InitializeEx. Looks like possible access to the uninitialized memory, which may lead to spurious crashes, security vulnerabilities etc.
The problem stably reproduces on the following trivial program:
#include <Python.h>
int main (void) {
Py_InitializeEx(1);
return 0;
}
Build flags are:
clang -I/usr/include/python3.13 -lpython3.13 -fsanitize=memory -o test test.c
I use python3-3.13.3-2.fc41.x86_64 on Fedora 41 and python3-3.13.3-2.fc42.x86_64 on Fedora 42 with the same result.
When runt, the program prints the following error message, caught by the memory sanitizer:
$ ./test
Uninitialized bytes in strlen at offset 3 inside [0x701000000060, 8)
==885210==WARNING: MemorySanitizer: use-of-uninitialized-value
#0 0x7f9ac021aee1 (/lib64/libpython3.13.so.1.0+0x21aee1) (BuildId: 1c4c8d9438e8b8152cd998abe09c43e52d4df6c4)
#1 0x7f9ac0123341 (/lib64/libpython3.13.so.1.0+0x123341) (BuildId: 1c4c8d9438e8b8152cd998abe09c43e52d4df6c4)
#2 0x7f9ac021abb8 (/lib64/libpython3.13.so.1.0+0x21abb8) (BuildId: 1c4c8d9438e8b8152cd998abe09c43e52d4df6c4)
#3 0x7f9ac021acbd (/lib64/libpython3.13.so.1.0+0x21acbd) (BuildId: 1c4c8d9438e8b8152cd998abe09c43e52d4df6c4)
#4 0x7f9ac021a9e1 (/lib64/libpython3.13.so.1.0+0x21a9e1) (BuildId: 1c4c8d9438e8b8152cd998abe09c43e52d4df6c4)
#5 0x7f9ac0219002 (/lib64/libpython3.13.so.1.0+0x219002) (BuildId: 1c4c8d9438e8b8152cd998abe09c43e52d4df6c4)
#6 0x7f9ac02149fe (/lib64/libpython3.13.so.1.0+0x2149fe) (BuildId: 1c4c8d9438e8b8152cd998abe09c43e52d4df6c4)
#7 0x7f9ac020e720 (/lib64/libpython3.13.so.1.0+0x20e720) (BuildId: 1c4c8d9438e8b8152cd998abe09c43e52d4df6c4)
#8 0x7f9ac020e02a in Py_InitializeFromConfig (/lib64/libpython3.13.so.1.0+0x20e02a) (BuildId: 1c4c8d9438e8b8152cd998abe09c43e52d4df6c4)
#9 0x7f9ac011ed98 in Py_InitializeEx (/lib64/libpython3.13.so.1.0+0x11ed98) (BuildId: 1c4c8d9438e8b8152cd998abe09c43e52d4df6c4)
#10 0x00000049ae4f in main (/home/pzz/tmp/msan/test+0x49ae4f) (BuildId: 5eddd7e5f7ffc7204c1417ebfc545f77a3fab253)
#11 0x7f9abfde1247 in __libc_start_call_main (/lib64/libc.so.6+0x3247) (BuildId: b840d32d15506ed2f29610c7f512d9084f2d7d69)
#12 0x7f9abfde130a in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x330a) (BuildId: b840d32d15506ed2f29610c7f512d9084f2d7d69)
#13 0x000000401314 in _start (/home/pzz/tmp/msan/test+0x401314) (BuildId: 5eddd7e5f7ffc7204c1417ebfc545f77a3fab253)
SUMMARY: MemorySanitizer: use-of-uninitialized-value (/lib64/libpython3.13.so.1.0+0x21aee1) (BuildId: 1c4c8d9438e8b8152cd998abe09c43e52d4df6c4)
Exiting
If some more technical details are required, feel free to ask.
Thanks in advance!
CPython versions tested on:
3.13
Operating systems tested on:
Linux