File 1429-erts-Ensure-erl_poll-can-handle-huge-timeouts.patch of Package erlang

From 5f17b6cc2cd1aff6d5baa401837d0c2036f78ade Mon Sep 17 00:00:00 2001
From: Rickard Green <rickard@erlang.org>
Date: Sat, 23 Dec 2023 22:53:21 +0100
Subject: [PATCH 3/3] [erts] Ensure erl_poll can handle huge timeouts

---
 erts/emulator/sys/common/erl_poll.c | 11 +++++++++--
 erts/emulator/sys/win32/erl_poll.c  | 11 ++++++++++-
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/erts/emulator/sys/common/erl_poll.c b/erts/emulator/sys/common/erl_poll.c
index ecf0d684c2..66e72ef196 100644
--- a/erts/emulator/sys/common/erl_poll.c
+++ b/erts/emulator/sys/common/erl_poll.c
@@ -1809,8 +1809,15 @@ get_timeout_timespec(ErtsPollSet *ps,
     }
     else {
 	ErtsMonotonicTime sec = timeout/(1000*1000*1000);
-	tsp->tv_sec = sec;
-	tsp->tv_nsec = timeout - sec*(1000*1000*1000);
+        if (sizeof(tsp->tv_sec) == 8
+            || sec <= (ErtsMonotonicTime) INT_MAX) {
+            tsp->tv_sec = sec;
+            tsp->tv_nsec = timeout - sec*(1000*1000*1000);
+        }
+        else {
+            tsp->tv_sec = INT_MAX;
+            tsp->tv_nsec = 0;
+        }
 
 	ASSERT(tsp->tv_sec >= 0);
 	ASSERT(tsp->tv_nsec >= 0);
diff --git a/erts/emulator/sys/win32/erl_poll.c b/erts/emulator/sys/win32/erl_poll.c
index 3843a27a6e..2a5638cecf 100644
--- a/erts/emulator/sys/win32/erl_poll.c
+++ b/erts/emulator/sys/win32/erl_poll.c
@@ -1015,6 +1015,8 @@ ErtsPollEvents erts_poll_control(ErtsPollSet *ps,
     return result;
 }
 
+#define MILLISECONDS_PER_WEEK__ (7*24*60*60*1000)
+
 int erts_poll_wait(ErtsPollSet *ps,
 		   ErtsPollResFd pr[],
 		   int *len,
@@ -1022,7 +1024,7 @@ int erts_poll_wait(ErtsPollSet *ps,
                    Sint64 timeout_in)
 {
     int no_fds;
-    DWORD timeout = timeout_in == -1 ? INFINITE : timeout_in;
+    DWORD timeout;
     EventData* ev;
     int res = 0;
     int num = 0;
@@ -1030,6 +1032,13 @@ int erts_poll_wait(ErtsPollSet *ps,
     int i;
     int break_state;
 
+    if (timeout_in < 0)
+        timeout = INFINITE;
+    else if (timeout_in > MILLISECONDS_PER_WEEK__)
+        timeout = MILLISECONDS_PER_WEEK__;
+    else
+        timeout = (DWORD) timeout_in;
+
     HARDTRACEF(("In erts_poll_wait"));
     ERTS_POLLSET_LOCK(ps);
 
-- 
2.35.3

openSUSE Build Service is sponsored by