select: avoid a NULL deref in cwfds_add_sock

curl_multi_waitfds(m, NULL, ...);

=> Curl_waitfds_init(&cwfds, ufds, size);

=> Curl_waitfds_add_ps(&cwfds);

=>   cwfds_add_sock(cwfds, ...);

Would then try to use the ->wfds array while set to NULL previously.
This should not happen, which this is now also protected with an assert
to trigger debug builds if it happens.

Caught by CodeSonar

Assisted-by: Jay Satiro

Closes #15881
This commit is contained in:
Daniel Stenberg 2025-01-01 01:00:33 +01:00
parent 26a672260b
commit af4e85925d
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2

View File

@ -503,7 +503,10 @@ static unsigned int cwfds_add_sock(struct curl_waitfds *cwfds,
curl_socket_t sock, short events)
{
int i;
if(!cwfds->wfds) {
DEBUGASSERT(!cwfds->count && !cwfds->n);
return 1;
}
if(cwfds->n <= INT_MAX) {
for(i = (int)cwfds->n - 1; i >= 0; --i) {
if(sock == cwfds->wfds[i].fd) {