]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
sysdeps-pthread: Fix timeout overflow adjustment
authorJohan Bolmsjö <dev@johan.bitmaster.se>
Fri, 11 Jul 2025 20:08:23 +0000 (22:08 +0200)
committerSimon McVittie <smcv@collabora.com>
Mon, 11 Aug 2025 13:08:34 +0000 (14:08 +0100)
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 <smcv@collabora.com>
dbus/dbus-sysdeps-pthread.c

index 3955a0d3f375b9c00ffcc9a97801f3c8673d61c1..839d7b28434dbba85277560fe13234e473740b2a 100644 (file)
@@ -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;