From: Johan Bolmsjö Date: Fri, 11 Jul 2025 20:08:23 +0000 (+0200) Subject: sysdeps-pthread: Fix timeout overflow adjustment X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1d73f69afbb0af5e8ea9ddee47cb84935a198e0b;p=thirdparty%2Fdbus.git 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 --- diff --git a/dbus/dbus-sysdeps-pthread.c b/dbus/dbus-sysdeps-pthread.c index 3955a0d3f..839d7b284 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;