commit-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[hurd,commited] mach: Fix bogus negative return


From: Samuel Thibault
Subject: [hurd,commited] mach: Fix bogus negative return
Date: Sun, 25 Aug 2024 03:38:16 +0200

One can be very unlucky to call time_now first just before a second switch,
and mach_msg sleep just a bit more enough for the second time_now call to
count one second too many (or even more if scheduling is really unlucky).

So we have to protect against returning a bogus negative value in such case.
---
 sysdeps/mach/sleep.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/sysdeps/mach/sleep.c b/sysdeps/mach/sleep.c
index 572be150bc..aa750c13c5 100644
--- a/sysdeps/mach/sleep.c
+++ b/sysdeps/mach/sleep.c
@@ -43,6 +43,9 @@ __sleep (unsigned int seconds)
   after = time_now ();
   __mach_port_destroy (__mach_task_self (), recv);
 
+  if (after - before > seconds)
+    return 0;
+
   return seconds - (after - before);
 }
 weak_alias (__sleep, sleep)
-- 
2.43.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]