wutsocket fixes: select() handles timeout wrong, and poll() lacks a safety check #428
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The main issue fixed here is the incompatible implementation of
select()in nsysnet: for BSDselect(), on timeout (zero return value) it's supposed to clear thefd_setarguments. As far as I could test, nsysnetselect()leaves the arguments untouched on timeout; so the latter part of wutoscketselect()will simply add the sockets back to thefd_sets. An early return, after the arguments are zeroed, is enough to ensure the correct result.Also in
select(), the check againstFD_SETSIZEwas removed, as it's a pointless restriction. If the user exceededFD_SETSIZEin the arguments, we're already in undefined behavior territory, and the runtime stack was already overflown before even callingselect().The definition of
FD_SETSIZEis now conditional, allowing it to be a custom limit, as it was always intended. The definition offd_setin newlib is an array that usesFD_SETSIZE.Both
select()andpoll()received a check againstNSYSNET_FD_SETSIZE, to avoid callingNSYSNET_FD_SETwith an invalid fd. Even though it's just setting a bit in auint32_t(instead of writing to an array of incorrect size), bit-shifts larger than the type are undefined behavior.