Since we need to have a release because of the OpenSSL legalese, we
can as well fix the most important (crashing) bugs in 1.8.1.  I have
opened a branch named `branch-1_8_2' where the 1.8.2-specific changes
will be applied.

Note that only bug fixes will be accepted for 1.8.2.  No new features.
Here are the patches that I plan to apply initially.  Please let me
know if you have more.

Only in wget-1.8.1-patched/src: fl
diff -ru wget-1.8.1/src/gen_sslfunc.c wget-1.8.1-patched/src/gen_sslfunc.c
--- wget-1.8.1/src/gen_sslfunc.c        Mon Dec 17 15:05:08 2001
+++ wget-1.8.1-patched/src/gen_sslfunc.c        Sat Apr 13 01:01:30 2002
@@ -221,9 +221,8 @@
   do
     {
 #ifdef HAVE_SELECT
-      if (opt.timeout)
+      if (opt.timeout && !SSL_pending (con))
        {
-         
          do
            {
              res = select_fd (fd, opt.timeout, 0);
diff -ru wget-1.8.1/src/headers.c wget-1.8.1-patched/src/headers.c
--- wget-1.8.1/src/headers.c    Fri Nov 16 20:57:43 2001
+++ wget-1.8.1-patched/src/headers.c    Sat Apr 13 01:08:02 2002
@@ -64,8 +64,8 @@
    as much memory as necessary for it to fit.  It need not contain a
    `:', thus you can use it to retrieve, say, HTTP status line.
 
-   The trailing CRLF or LF are stripped from the header, and it is
-   zero-terminated.   #### Is this well-behaved?  */
+   All trailing whitespace is stripped from the header, and it is
+   zero-terminated.  */
 int
 header_get (struct rbuf *rbuf, char **hdr, enum header_get_flags flags)
 {
@@ -101,11 +101,13 @@
                  if (next == '\t' || next == ' ')
                    continue;
                }
-             /* The header ends.  */
+
+             /* Strip trailing whitespace.  (*hdr)[i] is the newline;
+                decrement I until it points to the last available
+                whitespace.  */
+             while (i > 0 && ISSPACE ((*hdr)[i - 1]))
+               --i;
              (*hdr)[i] = '\0';
-             /* Get rid of '\r'.  */
-             if (i > 0 && (*hdr)[i - 1] == '\r')
-               (*hdr)[i - 1] = '\0';
              break;
            }
        }
diff -ru wget-1.8.1/src/html-url.c wget-1.8.1-patched/src/html-url.c
--- wget-1.8.1/src/html-url.c   Wed Dec 19 02:15:34 2001
+++ wget-1.8.1-patched/src/html-url.c   Sat Apr 13 00:59:02 2002
@@ -521,10 +521,13 @@
         get to the URL.  */
 
       struct urlpos *entry;
-
       int attrind;
-      char *p, *refresh = find_attr (tag, "content", &attrind);
       int timeout = 0;
+      char *p;
+
+      char *refresh = find_attr (tag, "content", &attrind);
+      if (!refresh)
+       return;
 
       for (p = refresh; ISDIGIT (*p); p++)
        timeout = 10 * timeout + *p - '0';
diff -ru wget-1.8.1/src/http.c wget-1.8.1-patched/src/http.c
--- wget-1.8.1/src/http.c       Thu Dec 13 17:46:56 2001
+++ wget-1.8.1-patched/src/http.c       Sat Apr 13 01:05:20 2002
@@ -1215,6 +1215,8 @@
              /* In case the caller inspects. */
              hs->len = contlen;
              hs->res = 0;
+             /* Mark as successfully retrieved. */
+             *dt |= RETROKF;
              FREE_MAYBE (type);
              FREE_MAYBE (all_headers);
              CLOSE_INVALIDATE (sock);  /* would be CLOSE_FINISH, but there
@@ -1357,6 +1359,11 @@
                          (contlen != -1 ? contlen : 0),
                          &rbuf, keep_alive, &hs->dltime);
 
+  if (hs->res >= 0)
+    CLOSE_FINISH (sock);
+  else
+    CLOSE_INVALIDATE (sock);
+
   {
     /* Close or flush the file.  We have to be careful to check for
        error here.  Checking the result of fwrite() is not enough --
@@ -1370,7 +1377,6 @@
       hs->res = -2;
   }
   FREE_MAYBE (all_headers);
-  CLOSE_FINISH (sock);
   if (hs->res == -2)
     return FWRITEERR;
   return RETRFINISHED;
Only in wget-1.8.1-patched/src: http.c.orig
diff -ru wget-1.8.1/src/netrc.c wget-1.8.1-patched/src/netrc.c
--- wget-1.8.1/src/netrc.c      Fri Nov 30 10:33:22 2001
+++ wget-1.8.1-patched/src/netrc.c      Sat Apr 13 01:01:58 2002
@@ -280,6 +280,10 @@
       p = line;
       quote = 0;
 
+      /* Skip leading whitespace.  */
+      while (*p && ISSPACE (*p))
+       p ++;
+
       /* If the line is empty, then end any macro definition.  */
       if (last_token == tok_macdef && !*p)
        /* End of macro if the line is empty.  */
diff -ru wget-1.8.1/src/recur.c wget-1.8.1-patched/src/recur.c
--- wget-1.8.1/src/recur.c      Wed Dec 19 15:27:29 2001
+++ wget-1.8.1-patched/src/recur.c      Sat Apr 13 00:57:08 2002
@@ -186,15 +186,24 @@
   uerr_t status = RETROK;
 
   /* The queue of URLs we need to load. */
-  struct url_queue *queue = url_queue_new ();
+  struct url_queue *queue;
 
   /* The URLs we do not wish to enqueue, because they are already in
      the queue, but haven't been downloaded yet.  */
-  struct hash_table *blacklist = make_string_hash_table (0);
+  struct hash_table *blacklist;
 
-  /* We'll need various components of this, so better get it over with
-     now. */
-  struct url *start_url_parsed = url_parse (start_url, NULL);
+  int up_error_code;
+  struct url *start_url_parsed = url_parse (start_url, &up_error_code);
+
+  if (!start_url_parsed)
+    {
+      logprintf (LOG_NOTQUIET, "%s: %s.\n", start_url,
+                url_error (up_error_code));
+      return URLERROR;
+    }
+
+  queue = url_queue_new ();
+  blacklist = make_string_hash_table (0);
 
   /* Enqueue the starting URL.  Use start_url_parsed->url rather than
      just URL so we enqueue the canonical form of the URL.  */
diff -ru wget-1.8.1/src/url.c wget-1.8.1-patched/src/url.c
--- wget-1.8.1/src/url.c        Fri Dec 14 16:45:59 2001
+++ wget-1.8.1-patched/src/url.c        Sat Apr 13 01:04:37 2002
@@ -528,6 +528,11 @@
   memcpy (*user, str, len);
   (*user)[len] = '\0';
 
+  if (*user)
+    decode_string (*user);
+  if (*passwd)
+    decode_string (*passwd);
+
   return 1;
 }
 
@@ -1574,6 +1579,35 @@
          memcpy (constr, base, baselength);
          memcpy (constr + baselength, link, linklength);
          constr[baselength + linklength] = '\0';
+       }
+      else if (linklength > 1 && *link == '/' && *(link + 1) == '/')
+       {
+         /* LINK begins with "//" and so is a net path: we need to
+            replace everything after (and including) the double slash
+            with LINK.
+
+            So, if BASE is "http://oldhost/whatever/foo/bar";, and LINK
+            is "//newhost/qux/xyzzy", our result should be
+            "http://newhost/qux/xyzzy";.  */
+         int span;
+         const char *slash;
+         const char *start_insert;
+         /* Look for first slash. */
+         slash = memchr (base, '/', end - base);
+         /* If found slash and it is a double slash, then replace
+            from this point,
+            else default to replacing from the beginning.  */
+         if (slash && *(slash + 1) == '/')
+           start_insert = slash;
+         else
+           start_insert = base;
+
+         span = start_insert - base;
+         constr = (char *)xmalloc (span + linklength + 1);
+         if (span)
+           memcpy (constr, base, span);
+         memcpy (constr + span, link, linklength);
+         constr[span + linklength] = '\0';
        }
       else if (*link == '/')
        {
Only in wget-1.8.1-patched/src: url.c.orig
diff -ru wget-1.8.1/src/wget.h wget-1.8.1-patched/src/wget.h
--- wget-1.8.1/src/wget.h       Mon Dec 10 06:31:45 2001
+++ wget-1.8.1-patched/src/wget.h       Sat Apr 13 01:02:30 2002
@@ -251,8 +251,9 @@
        XREALLOC_ARRAY (basevar, type, do_realloc_newsize);                     \
       else                                                                     \
        {                                                                       \
-         void *drfa_new_basevar = xmalloc (do_realloc_newsize);                \
-         memcpy (drfa_new_basevar, basevar, (sizevar));                        \
+         void *drfa_new_basevar =                                              \
+               xmalloc (do_realloc_newsize * sizeof (type));                   \
+         memcpy (drfa_new_basevar, basevar, (sizevar) * sizeof (type));        \
          (basevar) = drfa_new_basevar;                                         \
          allocap = 0;                                                          \
        }                                                                       \

Reply via email to