From fdb6746d855fed34dfc88bafb353fa3c4ed8d905 Mon Sep 17 00:00:00 2001 From: Gleb Popov <6yearold@gmail.com> Date: Sat, 3 May 2025 17:10:23 +0300 Subject: [PATCH 1/2] dbus-connection: Avoid computing a negative timeout Getting into the `if (timeout == NULL)` block means that timeout_milliseconds == -1, so it doesn't make sense to do arithmetic on it. Pass -1 instead of a nonsensical value in this case --- dbus/dbus-connection.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dbus/dbus-connection.c b/dbus/dbus-connection.c index 53ca34a8..d6894e9a 100644 --- a/dbus/dbus-connection.c +++ b/dbus/dbus-connection.c @@ -2510,7 +2510,7 @@ _dbus_connection_block_pending_call (DBusPendingCall *pending) */ _dbus_verbose ("dbus_connection_send_with_reply_and_block() waiting for more memory\n"); - _dbus_memory_pause_based_on_timeout (timeout_milliseconds - elapsed_milliseconds); + _dbus_memory_pause_based_on_timeout (-1); } else { @@ -2519,7 +2519,7 @@ _dbus_connection_block_pending_call (DBusPendingCall *pending) pending, DBUS_ITERATION_DO_READING | DBUS_ITERATION_BLOCK, - timeout_milliseconds - elapsed_milliseconds); + -1); } goto recheck_status; From a834a877c68e330723192471bdb05eaae3300205 Mon Sep 17 00:00:00 2001 From: Gleb Popov <6yearold@gmail.com> Date: Thu, 8 May 2025 00:58:06 +0300 Subject: [PATCH 2/2] Assert that timeout >= 0 in _dbus_platform_condvar_wait_timeout --- dbus/dbus-sysdeps-pthread.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dbus/dbus-sysdeps-pthread.c b/dbus/dbus-sysdeps-pthread.c index f9c25604..3955a0d3 100644 --- a/dbus/dbus-sysdeps-pthread.c +++ b/dbus/dbus-sysdeps-pthread.c @@ -229,6 +229,8 @@ _dbus_platform_condvar_wait_timeout (DBusCondVar *cond, struct timespec end_time; int result; + _dbus_assert (timeout_milliseconds >= 0); + #ifdef HAVE_MONOTONIC_CLOCK if (have_monotonic_clock) {