avoid consuming 100% CPU when running traceroute in loop

Resolves: RHEL-71510
This commit is contained in:
Jan Macku 2024-12-18 13:29:15 +01:00
parent 940a2b692d
commit 0a66e5633c
2 changed files with 49 additions and 1 deletions

View File

@ -0,0 +1,44 @@
diff --color -u -r traceroute-2.1.0/traceroute/poll.c traceroute-2.1.1/traceroute/poll.c
--- traceroute-2.1.0/traceroute/poll.c 2016-03-07 17:20:56.000000000 +0100
+++ traceroute-2.1.1/traceroute/poll.c 2022-12-27 01:00:18.000000000 +0100
@@ -64,28 +64,23 @@
void do_poll (double timeout, void (*callback) (int fd, int revents)) {
- int nfds;
- int msecs = ceil (timeout * 1000);
+ int nfds, n, i;
- while ((nfds = cleanup_polls ()) > 0) {
- int i, n;
+ nfds = cleanup_polls ();
- n = poll (pfd, nfds, msecs);
+ if (!nfds) return;
- if (n <= 0) {
- if (n == 0 || errno == EINTR)
- return;
- error ("poll");
- }
+ n = poll (pfd, nfds, ceil(timeout * 1000));
+ if (n < 0) {
+ if (errno == EINTR) return;
+ error ("poll");
+ }
- for (i = 0; n && i < num_polls; i++) {
- if (pfd[i].revents) {
- callback (pfd[i].fd, pfd[i].revents);
- n--;
- }
+ for (i = 0; n && i < num_polls; i++) {
+ if (pfd[i].revents) {
+ callback (pfd[i].fd, pfd[i].revents);
+ n--;
}
-
- msecs = 0; /* no more wait, just eat all the pending */
}
return;

View File

@ -2,13 +2,14 @@ Summary: Traces the route taken by packets over an IPv4/IPv6 network
Name: traceroute
Epoch: 3
Version: 2.1.0
Release: 8%{?dist}
Release: 9%{?dist}
Group: Applications/Internet
License: GPLv2+
URL: http://traceroute.sourceforge.net
Source0: http://downloads.sourceforge.net/project/traceroute/traceroute/traceroute-%{version}/traceroute-%{version}.tar.gz
Patch001: 001-traceroute-CVE-2023-46316.patch
Patch002: 002-traceroute-2.1.1-return-back-more-robust.patch
Provides: tcptraceroute = 1.5-1
Obsoletes: tcptraceroute < 1.5-1
@ -61,6 +62,9 @@ popd
%changelog
* Wed Dec 18 2024 Jan Macku <jamacku@redhat.com> - 3:2.1.0-9
- avoid consuming 100% CPU when running traceroute in loop (RHEL-71510)
* Mon Nov 27 2023 Jan Macku <jamacku@redhat.com> - 3:2.1.0-8
- add gating.yaml