From 6895126a6829a0ed4699d1127b5bccb9555dbffe Mon Sep 17 00:00:00 2001 From: hniksic Date: Tue, 21 Jun 2005 18:06:48 -0700 Subject: [PATCH] [svn] Fix crash with --no-cookies. --- src/ChangeLog | 7 +++++++ src/http.c | 47 ++++++++++++++++++++++++----------------------- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 01401296..927be724 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2005-06-22 Hrvoje Niksic + + * 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! + 2005-06-22 Hrvoje Niksic * connect.c (select_fd): Expect select() to exist. diff --git a/src/http.c b/src/http.c index 06c3c5bd..007f0096 100644 --- a/src/http.c +++ b/src/http.c @@ -1704,29 +1704,30 @@ gethttp (struct url *u, struct http_stat *hs, int *dt, struct url *proxy) 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))) {