Blame SOURCES/0040-curl-7.29.0-513e587c.patch

105fd7
From 070718b3e00d0341d44dd5ad4b48fd4468d047c6 Mon Sep 17 00:00:00 2001
105fd7
From: Daniel Stenberg <daniel@haxx.se>
105fd7
Date: Sat, 9 Mar 2013 22:26:07 +0100
105fd7
Subject: [PATCH 1/3] curl_multi_wait: avoid second loop if nothing to do
105fd7
105fd7
... hopefully this will also make clang-analyzer stop warning on
105fd7
potentional NULL dereferences (which were false positives anyway).
105fd7
105fd7
Upstream-commit: 136a3a0ee25f28fec1dde216467389f9e6e4f65c
105fd7
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
105fd7
---
105fd7
 lib/multi.c | 55 ++++++++++++++++++++++++++++++++-----------------------
105fd7
 1 file changed, 32 insertions(+), 23 deletions(-)
105fd7
105fd7
diff --git a/lib/multi.c b/lib/multi.c
105fd7
index 6dfce9b..1136849 100644
105fd7
--- a/lib/multi.c
105fd7
+++ b/lib/multi.c
105fd7
@@ -804,7 +804,8 @@ CURLMcode curl_multi_wait(CURLM *multi_handle,
105fd7
   curl_socket_t sockbunch[MAX_SOCKSPEREASYHANDLE];
105fd7
   int bitmap;
105fd7
   unsigned int i;
105fd7
-  unsigned int nfds = extra_nfds;
105fd7
+  unsigned int nfds = 0;
105fd7
+  unsigned int curlfds;
105fd7
   struct pollfd *ufds = NULL;
105fd7
   long timeout_internal;
105fd7
 
105fd7
@@ -842,6 +843,9 @@ CURLMcode curl_multi_wait(CURLM *multi_handle,
105fd7
     easy = easy->next; /* check next handle */
105fd7
   }
105fd7
 
105fd7
+  curlfds = nfds; /* number of internal file descriptors */
105fd7
+  nfds += extra_nfds; /* add the externally provided ones */
105fd7
+
105fd7
   if(nfds) {
105fd7
     ufds = malloc(nfds * sizeof(struct pollfd));
105fd7
     if(!ufds)
105fd7
@@ -849,32 +853,37 @@ CURLMcode curl_multi_wait(CURLM *multi_handle,
105fd7
   }
105fd7
   nfds = 0;
105fd7
 
105fd7
-  /* Add the curl handles to our pollfds first */
105fd7
-  easy=multi->easy.next;
105fd7
-  while(easy != &multi->easy) {
105fd7
-    bitmap = multi_getsock(easy, sockbunch, MAX_SOCKSPEREASYHANDLE);
105fd7
+  /* only do the second loop if we found descriptors in the first stage run
105fd7
+     above */
105fd7
 
105fd7
-    for(i=0; i< MAX_SOCKSPEREASYHANDLE; i++) {
105fd7
-      curl_socket_t s = CURL_SOCKET_BAD;
105fd7
+  if(curlfds) {
105fd7
+    /* Add the curl handles to our pollfds first */
105fd7
+    easy=multi->easy.next;
105fd7
+    while(easy != &multi->easy) {
105fd7
+      bitmap = multi_getsock(easy, sockbunch, MAX_SOCKSPEREASYHANDLE);
105fd7
 
105fd7
-      if(bitmap & GETSOCK_READSOCK(i)) {
105fd7
-        ufds[nfds].fd = sockbunch[i];
105fd7
-        ufds[nfds].events = POLLIN;
105fd7
-        ++nfds;
105fd7
-        s = sockbunch[i];
105fd7
-      }
105fd7
-      if(bitmap & GETSOCK_WRITESOCK(i)) {
105fd7
-        ufds[nfds].fd = sockbunch[i];
105fd7
-        ufds[nfds].events = POLLOUT;
105fd7
-        ++nfds;
105fd7
-        s = sockbunch[i];
105fd7
-      }
105fd7
-      if(s == CURL_SOCKET_BAD) {
105fd7
-        break;
105fd7
+      for(i=0; i< MAX_SOCKSPEREASYHANDLE; i++) {
105fd7
+        curl_socket_t s = CURL_SOCKET_BAD;
105fd7
+
105fd7
+        if(bitmap & GETSOCK_READSOCK(i)) {
105fd7
+          ufds[nfds].fd = sockbunch[i];
105fd7
+          ufds[nfds].events = POLLIN;
105fd7
+          ++nfds;
105fd7
+          s = sockbunch[i];
105fd7
+        }
105fd7
+        if(bitmap & GETSOCK_WRITESOCK(i)) {
105fd7
+          ufds[nfds].fd = sockbunch[i];
105fd7
+          ufds[nfds].events = POLLOUT;
105fd7
+          ++nfds;
105fd7
+          s = sockbunch[i];
105fd7
+        }
105fd7
+        if(s == CURL_SOCKET_BAD) {
105fd7
+          break;
105fd7
+        }
105fd7
       }
105fd7
-    }
105fd7
 
105fd7
-    easy = easy->next; /* check next handle */
105fd7
+      easy = easy->next; /* check next handle */
105fd7
+    }
105fd7
   }
105fd7
 
105fd7
   /* Add external file descriptions from poll-like struct curl_waitfd */
105fd7
-- 
105fd7
2.5.5
105fd7
105fd7
105fd7
From f8b84a52088a99d8128c2234f626ed233beabeae Mon Sep 17 00:00:00 2001
105fd7
From: Evgeny Turnaev <turnaev.e@gmail.com>
105fd7
Date: Thu, 18 Jul 2013 00:06:09 +0200
105fd7
Subject: [PATCH 2/3] curl_multi_wait: set revents for extra fds
105fd7
105fd7
Pass back the revents that happened for the user-provided file
105fd7
descriptors.
105fd7
105fd7
Upstream-commit: 6d30f8ebed34e7276c2a59ee20d466bff17fee56
105fd7
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
105fd7
---
105fd7
 lib/multi.c | 5 ++++-
105fd7
 1 file changed, 4 insertions(+), 1 deletion(-)
105fd7
105fd7
diff --git a/lib/multi.c b/lib/multi.c
105fd7
index 1136849..81bcfba 100644
105fd7
--- a/lib/multi.c
105fd7
+++ b/lib/multi.c
105fd7
@@ -803,7 +803,7 @@ CURLMcode curl_multi_wait(CURLM *multi_handle,
105fd7
   struct Curl_one_easy *easy;
105fd7
   curl_socket_t sockbunch[MAX_SOCKSPEREASYHANDLE];
105fd7
   int bitmap;
105fd7
-  unsigned int i;
105fd7
+  unsigned int i, j;
105fd7
   unsigned int nfds = 0;
105fd7
   unsigned int curlfds;
105fd7
   struct pollfd *ufds = NULL;
105fd7
@@ -905,6 +905,9 @@ CURLMcode curl_multi_wait(CURLM *multi_handle,
105fd7
   else
105fd7
     i = 0;
105fd7
 
105fd7
+  for(j = nfds - extra_nfds; j < nfds; j++)
105fd7
+    extra_fds[j].revents = ufds[j].revents;
105fd7
+
105fd7
   Curl_safefree(ufds);
105fd7
   if(ret)
105fd7
     *ret = i;
105fd7
-- 
105fd7
2.5.5
105fd7
105fd7
105fd7
From db2e5b5ffe5408aa892dee9e7f036fe0ea16963d Mon Sep 17 00:00:00 2001
105fd7
From: Daniel Stenberg <daniel@haxx.se>
105fd7
Date: Thu, 18 Jul 2013 23:36:59 +0200
105fd7
Subject: [PATCH 3/3] curl_multi_wait: fix revents
105fd7
105fd7
Commit 6d30f8ebed34e7276 didn't work properly. First, it used the wrong
105fd7
array index, but this fix also:
105fd7
105fd7
1 - only does the copying if indeed there was any activity
105fd7
105fd7
2 - makes sure to properly translate between internal and external
105fd7
bitfields, which are not guaranteed to match
105fd7
105fd7
Reported-by: Evgeny Turnaev
105fd7
105fd7
Upstream-commit: 513e587c5eb966038731530c8f47fe0cf27513ce
105fd7
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
105fd7
---
105fd7
 lib/multi.c | 28 +++++++++++++++++++++++-----
105fd7
 1 file changed, 23 insertions(+), 5 deletions(-)
105fd7
105fd7
diff --git a/lib/multi.c b/lib/multi.c
105fd7
index 81bcfba..0e0bb19 100644
105fd7
--- a/lib/multi.c
105fd7
+++ b/lib/multi.c
105fd7
@@ -803,7 +803,7 @@ CURLMcode curl_multi_wait(CURLM *multi_handle,
105fd7
   struct Curl_one_easy *easy;
105fd7
   curl_socket_t sockbunch[MAX_SOCKSPEREASYHANDLE];
105fd7
   int bitmap;
105fd7
-  unsigned int i, j;
105fd7
+  unsigned int i;
105fd7
   unsigned int nfds = 0;
105fd7
   unsigned int curlfds;
105fd7
   struct pollfd *ufds = NULL;
105fd7
@@ -899,15 +899,33 @@ CURLMcode curl_multi_wait(CURLM *multi_handle,
105fd7
     ++nfds;
105fd7
   }
105fd7
 
105fd7
-  if(nfds)
105fd7
+  if(nfds) {
105fd7
     /* wait... */
105fd7
     i = Curl_poll(ufds, nfds, timeout_ms);
105fd7
+
105fd7
+    if(i) {
105fd7
+      unsigned int j;
105fd7
+      /* copy revents results from the poll to the curl_multi_wait poll
105fd7
+         struct, the bit values of the actual underlying poll() implementation
105fd7
+         may not be the same as the ones in the public libcurl API! */
105fd7
+      for(j = 0; j < extra_nfds; j++) {
105fd7
+        unsigned short mask = 0;
105fd7
+        unsigned r = ufds[curlfds + j].revents;
105fd7
+
105fd7
+        if(r & POLLIN)
105fd7
+          mask |= CURL_WAIT_POLLIN;
105fd7
+        if(r & POLLOUT)
105fd7
+          mask |= CURL_WAIT_POLLOUT;
105fd7
+        if(r & POLLPRI)
105fd7
+          mask |= CURL_WAIT_POLLPRI;
105fd7
+
105fd7
+        extra_fds[j].revents = mask;
105fd7
+      }
105fd7
+    }
105fd7
+  }
105fd7
   else
105fd7
     i = 0;
105fd7
 
105fd7
-  for(j = nfds - extra_nfds; j < nfds; j++)
105fd7
-    extra_fds[j].revents = ufds[j].revents;
105fd7
-
105fd7
   Curl_safefree(ufds);
105fd7
   if(ret)
105fd7
     *ret = i;
105fd7
-- 
105fd7
2.5.5
105fd7