#1028649 Segmentation fault invoking bus.get_unique_name()

Package:
python3-pystemd
Source:
python3-pystemd
Description:
systemd binding for Python
Submitter:
Michael Deegan
Date:
2023-01-30 10:45:03 UTC
Severity:
normal
#1028649#5
Date:
2023-01-14 09:08:40 UTC
From:
To:
I'm open to the possibility I'm doing something wrong, but either way, I'm
pretty sure it shouldn't result in SEGV. Hopefully not an abusable buffer
overflow or similar?

    michael@joyola:~$ python3
    Python 3.10.9 (main, Dec  7 2022, 13:47:07) [GCC 12.2.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from pystemd.dbuslib import DBus
    >>> bus=DBus(user_mode=True)
    >>> bus.get_unique_name()
    pystemd.dbusexc.DBusBaseError: [err -22]: Failed to get unique name
    This is DBusBaseError, a base error for DBus (i bet you did not see that coming) if you need a special error, enhance pystemd.sysdexc module!.
    Exception ignored in: 'pystemd.dbuslib.DBus.get_unique_name'
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    pystemd.dbusexc.DBusBaseError: [err -22]: Failed to get unique name
    This is DBusBaseError, a base error for DBus (i bet you did not see that coming) if you need a special error, enhance pystemd.sysdexc module!.
    Segmentation fault

#1028649#10
Date:
2023-01-17 03:26:25 UTC
From:
To:
FWIW this bug still exists with version 0.11.0 installed via pip.
#1028649#15
Date:
2023-01-30 10:44:13 UTC
From:
To:
Dear Maintainer,
this can be reproduced in current Bookworm/testing too.

The backtrace below shows PyBytes_FromString received for
parameter str a NULL, which documentation states must not be NULL [1].

Unfortunately could not find an issue or update in upstream page [2].

Kind regards,
Bernhard



[1] https://docs.python.org/3/c-api/bytes.html
[2] https://github.com/facebookincubator/pystemd


$ cat test.py
from pystemd.dbuslib import DBus
bus=DBus(user_mode=True)
bus.get_unique_name()
$


$ python3 test.py
pystemd.dbusexc.DBusBaseError: [err -22]: Failed to get unique name
This is DBusBaseError, a base error for DBus (i bet you did not see that coming) if you need a special error, enhance pystemd.sysdexc module!.
Exception ignored in: 'pystemd.dbuslib.DBus.get_unique_name'
Traceback (most recent call last):
   File "/home/benutzer/test.py", line 3, in <module>
     bus.get_unique_name()
pystemd.dbusexc.DBusBaseError: [err -22]: Failed to get unique name
This is DBusBaseError, a base error for DBus (i bet you did not see that coming) if you need a special error, enhance pystemd.sysdexc module!.
Speicherzugriffsfehler (Speicherabzug geschrieben)
$


# coredumpctl gdb 1246
(gdb) bt
#0  __strlen_avx2 () at ../sysdeps/x86_64/multiarch/strlen-avx2.S:76
#1  0x000000000059f40c in PyBytes_FromString (str=0x0) at ../Objects/bytesobject.c:153
#2  0x00007f360fb7b6a6 in __pyx_pf_7pystemd_7dbuslib_4DBus_20get_unique_name (__pyx_v_self=<optimized out>) at pystemd/dbuslib.c:10541
#3  __pyx_pw_7pystemd_7dbuslib_4DBus_21get_unique_name (__pyx_v_self=<optimized out>, unused=<optimized out>) at pystemd/dbuslib.c:10525
#4  0x000000000055a850 in method_vectorcall_NOARGS (func=<method_descriptor at remote 0x7f360fbc3ba0>, args=0x7f3610512070, nargsf=<optimized out>, kwnames=0x0) at ../Objects/descrobject.c:453
#5  0x000000000053983c in _PyObject_VectorcallTstate (kwnames=<optimized out>, nargsf=<optimized out>, args=<optimized out>, callable=<method_descriptor at remote 0x7f360fbc3ba0>, tstate=0xa85258 <_PyRuntime+166328>) at ../Include/internal/pycore_call.h:92
#6  PyObject_Vectorcall (callable=<method_descriptor at remote 0x7f360fbc3ba0>, args=<optimized out>, nargsf=<optimized out>, kwnames=<optimized out>) at ../Objects/call.c:299
...
(gdb) py-bt
Traceback (most recent call first):
   File "/home/benutzer/test.py", line 3, in <module>
     bus.get_unique_name()
(gdb)


$ cat -n pystemd/dbuslib.c | grep 10541 -C10
  10531
  10532  static PyObject *__pyx_pf_7pystemd_7dbuslib_4DBus_20get_unique_name(struct __pyx_obj_7pystemd_7dbuslib_DBus *__pyx_v_self) {
  10533    PyObject *__pyx_r = NULL;
  10534    __Pyx_RefNannyDeclarations
  10535    PyObject *__pyx_t_1 = NULL;
  10536    int __pyx_lineno = 0;
  10537    const char *__pyx_filename = NULL;
  10538    int __pyx_clineno = 0;
  10539    __Pyx_RefNannySetupContext("get_unique_name", 0);
  10540    __Pyx_XDECREF(__pyx_r);
  10541    __pyx_t_1 = __Pyx_PyBytes_FromString(__pyx_f_7pystemd_7dbuslib_4DBus_get_unique_name(__pyx_v_self, 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 526, __pyx_L1_error)
  10542    __Pyx_GOTREF(__pyx_t_1);
  10543    __pyx_r = __pyx_t_1;
  10544    __pyx_t_1 = 0;
  10545    goto __pyx_L0;
  10546
  10547    /* function exit code */
...
$


$ cat -n pystemd/dbuslib.pyx | grep 536 -C10
    526      cpdef const char* get_unique_name(self):
    527          cdef:
    528              int r
    529              const char *unique_name
    530
    531          r = dbusc.sd_bus_get_unique_name(self.bus, &unique_name)
    532
    533          if r < 0:
    534              raise DBusError(r, None, "Failed to get unique name")
    535
    536          return unique_name
    537
    538      cpdef int get_fd(self):
...
$