Fix 1.10 cookie crash
Hrvoje Niksic <[email protected]> Wed, 22 Jun 2005 03:06:15 +0200
| Newsgroups | gmane.comp.web.wget.patches |
|---|---|
| Message-ID | <[email protected]> |
This is a serious bug in Wget 1.10 that causes crashes with --no-cookies and --cookies=off. That this bug hasn't been reported a thousand times is a testament of how many users get new versions of softwares from distributions/ports/etc. This bug is applied to the 1.10 branch as well. 2005-06-22 Hrvoje Niksic <[email protected]> * http.c (gethttp): Only handle --set-cookies (and assert that cookie jar exists) if opt.cookies is true. Failure to do so triggered the assert when --no-cookies was used and the server sent a Set-Cookie header. Ouch! Index: src/http.c =================================================================== --- src/http.c (revision 1734) +++ src/http.c (working copy) @@ -1704,29 +1704,30 @@ hs->remote_time = resp_header_strdup (resp, "Last-Modified"); /* Handle (possibly multiple instances of) the Set-Cookie header. */ - { - char *pth = NULL; - int scpos; - const char *scbeg, *scend; - /* The jar should have been created by now. */ - assert (wget_cookie_jar != NULL); - for (scpos = 0; - (scpos = resp_header_locate (resp, "Set-Cookie", scpos, - &scbeg, &scend)) != -1; - ++scpos) - { - char *set_cookie; BOUNDED_TO_ALLOCA (scbeg, scend, set_cookie); - if (pth == NULL) - { - /* u->path doesn't begin with /, which cookies.c expects. */ - pth = (char *) alloca (1 + strlen (u->path) + 1); - pth[0] = '/'; - strcpy (pth + 1, u->path); - } - cookie_handle_set_cookie (wget_cookie_jar, u->host, u->port, pth, - set_cookie); - } - } + if (opt.cookies) + { + char *pth = NULL; + int scpos; + const char *scbeg, *scend; + /* The jar should have been created by now. */ + assert (wget_cookie_jar != NULL); + for (scpos = 0; + (scpos = resp_header_locate (resp, "Set-Cookie", scpos, + &scbeg, &scend)) != -1; + ++scpos) + { + char *set_cookie; BOUNDED_TO_ALLOCA (scbeg, scend, set_cookie); + if (pth == NULL) + { + /* u->path doesn't begin with /, which cookies.c expects. */ + pth = (char *) alloca (1 + strlen (u->path) + 1); + pth[0] = '/'; + strcpy (pth + 1, u->path); + } + cookie_handle_set_cookie (wget_cookie_jar, u->host, u->port, pth, + set_cookie); + } + } if (resp_header_copy (resp, "Content-Range", hdrval, sizeof (hdrval))) {