From 77e172671998037d9d71f84b3b28a2fa1390daff Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 9 Mar 2016 10:57:42 +0100 Subject: curl_multi_wait: never return -1 in 'numfds' Such a return value isn't documented but could still happen, and the curl tool code checks for it. It would happen when the underlying Curl_poll() function returns an error. Starting now we mask that error as a user of curl_multi_wait() would have no way to handle it anyway. Reported-by: Jay Satiro Closes #707 --- lib/multi.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/multi.c b/lib/multi.c index ad7d21fea..6a1f7c82b 100644 --- a/lib/multi.c +++ b/lib/multi.c @@ -811,6 +811,7 @@ CURLMcode curl_multi_wait(CURLM *multi_handle, unsigned int curlfds; struct pollfd *ufds = NULL; long timeout_internal; + int retcode = 0; if(!GOOD_MULTI_HANDLE(multi)) return CURLM_BAD_HANDLE; @@ -903,18 +904,20 @@ CURLMcode curl_multi_wait(CURLM *multi_handle, } if(nfds) { + int pollrc; /* wait... */ - infof(data, "Curl_poll(%d ds, %d ms)\n", nfds, timeout_ms); - i = Curl_poll(ufds, nfds, timeout_ms); + pollrc = Curl_poll(ufds, nfds, timeout_ms); + DEBUGF(infof(data, "Curl_poll(%d ds, %d ms) == %d\n", + nfds, timeout_ms, pollrc)); - if(i) { - unsigned int j; + if(pollrc > 0) { + retcode = pollrc; /* copy revents results from the poll to the curl_multi_wait poll struct, the bit values of the actual underlying poll() implementation may not be the same as the ones in the public libcurl API! */ - for(j = 0; j < extra_nfds; j++) { + for(i = 0; i < extra_nfds; i++) { unsigned short mask = 0; - unsigned r = ufds[curlfds + j].revents; + unsigned r = ufds[curlfds + i].revents; if(r & POLLIN) mask |= CURL_WAIT_POLLIN; @@ -923,16 +926,14 @@ CURLMcode curl_multi_wait(CURLM *multi_handle, if(r & POLLPRI) mask |= CURL_WAIT_POLLPRI; - extra_fds[j].revents = mask; + extra_fds[i].revents = mask; } } } - else - i = 0; free(ufds); if(ret) - *ret = i; + *ret = retcode; return CURLM_OK; } -- cgit v1.2.3