Skip to content
Snippets Groups Projects
Commit 4cf587e6 authored by Sébastien Blin's avatar Sébastien Blin
Browse files

natpmp: avoid crash due to FD_SET

GitLab: #23
Change-Id: Ife39db96ee554adf547606c5e3a14fc53c13cda9
parent 45b50697
No related branches found
No related tags found
No related merge requests found
......@@ -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;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment