From 1d73f69afbb0af5e8ea9ddee47cb84935a198e0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Bolmsj=C3=B6?= Date: Fri, 11 Jul 2025 22:08:23 +0200 Subject: [PATCH] sysdeps-pthread: Fix timeout overflow adjustment Fix an off by one error which could produce a tv_nsec value of 1'000'000'000. The valid tv_nsec range is [0, 999,999,999], see https://en.cppreference.com/w/c/chrono/timespec for reference. Passing a timespec with a tv_nsec value of 1'000'000'000 to pthread_cond_timedwait has been observed to cause it to return an error code which in turn makes the DBUS library abort the application when compiled with asserts enabled (by PTHREAD_CHECK). Resolves: https://gitlab.freedesktop.org/dbus/dbus/-/issues/556 Reviewed-by: Simon McVittie --- dbus/dbus-sysdeps-pthread.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbus/dbus-sysdeps-pthread.c b/dbus/dbus-sysdeps-pthread.c index 3955a0d3..839d7b28 100644 --- a/dbus/dbus-sysdeps-pthread.c +++ b/dbus/dbus-sysdeps-pthread.c @@ -246,7 +246,7 @@ _dbus_platform_condvar_wait_timeout (DBusCondVar *cond, end_time.tv_sec = time_now.tv_sec + timeout_milliseconds / 1000; end_time.tv_nsec = (time_now.tv_usec + (timeout_milliseconds % 1000) * 1000) * 1000; - if (end_time.tv_nsec > 1000*1000*1000) + if (end_time.tv_nsec >= 1000*1000*1000) { end_time.tv_sec += 1; end_time.tv_nsec -= 1000*1000*1000;