From 4cf587e6741b62b144247321fcc77c07f06249f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Blin?= <sebastien.blin@savoirfairelinux.com> Date: Fri, 8 Mar 2024 16:00:18 -0500 Subject: [PATCH] natpmp: avoid crash due to FD_SET GitLab: #23 Change-Id: Ife39db96ee554adf547606c5e3a14fc53c13cda9 --- src/upnp/protocol/natpmp/nat_pmp.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/upnp/protocol/natpmp/nat_pmp.cpp b/src/upnp/protocol/natpmp/nat_pmp.cpp index 7e88ad7..c822b37 100644 --- a/src/upnp/protocol/natpmp/nat_pmp.cpp +++ b/src/upnp/protocol/natpmp/nat_pmp.cpp @@ -15,6 +15,7 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ #include "nat_pmp.h" +#include <poll.h> #if HAVE_LIBNATPMP @@ -333,13 +334,14 @@ NatPmp::readResponse(natpmp_t& handle, natpmpresp_t& response) break; } - fd_set fds; + struct pollfd fds; + fds.fd = handle.s; + fds.events = POLLIN; struct timeval timeout; - FD_ZERO(&fds); - FD_SET(handle.s, &fds); getnatpmprequesttimeout(&handle, &timeout); + uint64_t millis = (timeout.tv_sec * (uint64_t)1000) + (timeout.tv_usec / 1000); // Wait for data. - if (select(FD_SETSIZE, &fds, NULL, NULL, &timeout) == -1) { + if (poll(&fds, 1, millis) == -1) { err = NATPMP_ERR_SOCKETERROR; break; } -- GitLab