From 04b3c232702d98b89ab2748241aabdfe0a543a5d Mon Sep 17 00:00:00 2001 From: lilydjwg Date: Wed, 18 Oct 2023 21:30:05 +0800 Subject: [PATCH 1/2] fix DBusRemote using the wrong attribute --- pystemd/dbuslib.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pystemd/dbuslib.pyx b/pystemd/dbuslib.pyx index e88f58f..2fd8590 100644 --- a/pystemd/dbuslib.pyx +++ b/pystemd/dbuslib.pyx @@ -574,7 +574,7 @@ cdef class DBusRemote(DBus): self.host = host cdef int open_dbus_bus(self): - return dbusc.sd_bus_open_system_remote(&(self.bus), self.remote) + return dbusc.sd_bus_open_system_remote(&(self.bus), self.host) cdef class DBusAddress(DBus): "DBus class that connects to custom address" From cf2aeeca065c9d99a2f9f890fc2b87e55da92ed6 Mon Sep 17 00:00:00 2001 From: lilydjwg Date: Wed, 18 Oct 2023 22:15:43 +0800 Subject: [PATCH 2/2] DBusRemote: strdup host string to avoid use after free --- pystemd/dbuslib.pyx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pystemd/dbuslib.pyx b/pystemd/dbuslib.pyx index 2fd8590..e19ba1c 100644 --- a/pystemd/dbuslib.pyx +++ b/pystemd/dbuslib.pyx @@ -26,6 +26,7 @@ from libc.stdint cimport ( uint64_t, ) from libc.stdlib cimport free +from libc.string cimport strdup from libcpp cimport bool CONTAINER_TYPES = ( @@ -571,11 +572,14 @@ cdef class DBusRemote(DBus): cdef char* host def __init__(self, char* host): - self.host = host + self.host = strdup(host) cdef int open_dbus_bus(self): return dbusc.sd_bus_open_system_remote(&(self.bus), self.host) + def __dealloc__(self): + free(self.host) + cdef class DBusAddress(DBus): "DBus class that connects to custom address" cdef bytes address