mgr/PyFormatter: prevent segfault on non-printable characters
If PyFormatter::dump_string attempting to format non-printable characters can result in a nullptr being passed to dump_pyobject, causing a segfault. It occured in the following case - crash module tried to load the crash entries containing matedata with non-printable characters. when these were passed to PyFormatter, the resulting crash prevented ceph-mgr from starting. Fix this by attempting to create a python object using PyUnicode_FromString. If it returns nullptr (indicating a decoding failure), the code now falls back to decoding using Latin1. Additionally, add a guard in dump_pyobject to prevent processing nullptr objects, providing a secondary layer of protection against segfaults. Fixes: https://tracker.ceph.com/issues/74379 Signed-off-by: Nitzan Mordechai <nmordec@ibm.com>
N
NitzanMordhai committed
7c68a00cce5b7769c2e34fb7611d14825283fcda
Parent: 89d8d47