git: 01b661293975 - main - devel/tevent: clamp far-future poll(2) timeout to avoid a busy-loop

Jochen Neumeister <[email protected]>
Newsgroups gmane.os.freebsd.devel.cvs.ports
Message-ID <[email protected]>
The branch main has been updated by joneum:

URL: https://cgit.FreeBSD.org/ports/commit/?id=01b66129397537ff42403460f791b10e75ea9691

commit 01b66129397537ff42403460f791b10e75ea9691
Author:     Jochen Neumeister <[email protected]>
AuthorDate: 2026-08-12 22:14:16 +0000
Commit:     Jochen Neumeister <[email protected]>
CommitDate: 2026-08-12 22:14:16 +0000

    devel/tevent: clamp far-future poll(2) timeout to avoid a busy-loop
    
    When a timer is scheduled far enough in the future,
    tvalp->tv_sec * 1000 overflows the int millisecond value that
    poll_event_loop_poll() passes to poll(2). poll(2) then fails with
    EINVAL and tevent spins in a busy-loop instead of sleeping. Clamp
    the computed timeout to INT_MAX in that case.
    
    PR:             297401
    Approved by:    0mp (samba)
    Sponsored by:   Netzkommune GmbH
---
 devel/tevent/Makefile                   |  2 +-
 devel/tevent/files/patch-tevent__poll.c | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/devel/tevent/Makefile b/devel/tevent/Makefile
index ef6e4b8a1812..7ac5b1d05f18 100644
--- a/devel/tevent/Makefile
+++ b/devel/tevent/Makefile
@@ -1,6 +1,6 @@
 PORTNAME=			tevent
 DISTVERSION=			0.15.0
-PORTREVISION=			1
+PORTREVISION=			2
 PORTEPOCH=			0
 CATEGORIES=			devel
 MASTER_SITES=			SAMBA
diff --git a/devel/tevent/files/patch-tevent__poll.c b/devel/tevent/files/patch-tevent__poll.c
new file mode 100644
index 000000000000..fe285a375ca6
--- /dev/null
+++ b/devel/tevent/files/patch-tevent__poll.c
@@ -0,0 +1,18 @@
+--- tevent_poll.c.orig	2026-08-09 16:32:38 UTC
++++ tevent_poll.c
+@@ -470,8 +470,13 @@ static int poll_event_loop_poll(struct tevent_context 
+ 	}
+ 
+ 	if (tvalp != NULL) {
+-		timeout = tvalp->tv_sec * 1000;
+-		timeout += (tvalp->tv_usec + 999) / 1000;
++		/* clamp: far-future timer overflows int ms -> poll(2) EINVAL busy-loop */
++		if (tvalp->tv_sec > (INT_MAX / 1000) - 1) {
++			timeout = INT_MAX;
++		} else {
++			timeout = tvalp->tv_sec * 1000;
++			timeout += (tvalp->tv_usec + 999) / 1000;
++		}
+ 	}
+ 
+ 	ok = poll_event_sync_arrays(ev, poll_ev);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.