]> sjero.net Git - wget/commitdiff
gnutls: Fix a problem with multiple peek read calls.
authorGiuseppe Scrivano <gscrivano@gnu.org>
Thu, 29 Jul 2010 10:24:34 +0000 (12:24 +0200)
committerGiuseppe Scrivano <gscrivano@gnu.org>
Thu, 29 Jul 2010 10:24:34 +0000 (12:24 +0200)
src/ChangeLog
src/gnutls.c

index 60e82d944cf7a8a23d307552b25f1576698757de..30f75cd6d0c028fbc76adbf36ae79c4e791d272a 100644 (file)
@@ -1,3 +1,8 @@
+2010-07-29  Giuseppe Scrivano  <gscrivano@gnu.org>
+
+       * gnutls.c (wgnutls_peek): Don't read more data if the buffered peek
+       data is sufficient.
+
 2010-07-28  Giuseppe Scrivano  <gscrivano@gnu.org>
 
        * http.h (http_loop): Add new argument `original_url'
 2010-07-28  Giuseppe Scrivano  <gscrivano@gnu.org>
 
        * http.h (http_loop): Add new argument `original_url'
index adba856044e4f0eaa9bf9fc8906671c849d6e8c2..17c7c9287662b10292cc5c7b22babd33b3ae750e 100644 (file)
@@ -173,28 +173,33 @@ wgnutls_peek (int fd, char *buf, int bufsize, void *arg)
 {
   int ret = 0;
   struct wgnutls_transport_context *ctx = arg;
 {
   int ret = 0;
   struct wgnutls_transport_context *ctx = arg;
-  int offset = ctx->peeklen;
-
+  int offset = MIN (bufsize, ctx->peeklen);
   if (bufsize > sizeof ctx->peekbuf)
     bufsize = sizeof ctx->peekbuf;
 
   if (bufsize > sizeof ctx->peekbuf)
     bufsize = sizeof ctx->peekbuf;
 
-  if (offset)
+  if (ctx->peeklen)
     memcpy (buf, ctx->peekbuf, offset);
 
     memcpy (buf, ctx->peekbuf, offset);
 
-  do
+  if (bufsize > offset)
     {
     {
-      if (gnutls_record_check_pending (ctx->session)
-          || select_fd (fd, 0, WAIT_FOR_READ))
-        ret = gnutls_record_recv (ctx->session, buf + offset, bufsize - offset);
-    }
-  while (ret == GNUTLS_E_INTERRUPTED);
+      do
+        {
+          if (gnutls_record_check_pending (ctx->session)
+              || select_fd (fd, 0, WAIT_FOR_READ))
+            ret = gnutls_record_recv (ctx->session, buf + offset,
+                                      bufsize - offset);
+        }
+      while (ret == GNUTLS_E_INTERRUPTED);
 
 
-  if (ret > 0)
-    {
-      memcpy (ctx->peekbuf + offset, buf + offset, ret);
-      ctx->peeklen += ret;
+      if (ret > 0)
+        {
+          memcpy (ctx->peekbuf + offset, buf + offset,
+                  ret);
+          ctx->peeklen += ret;
+        }
     }
     }
-  return ctx->peeklen;
+
+  return offset + ret;
 }
 
 static const char *
 }
 
 static const char *