From 8bfafe2e7a62ab3be98f0043c698805c9c21dfc1 Mon Sep 17 00:00:00 2001 From: David Woodhouse Date: Tue, 31 Mar 2009 21:15:44 +0100 Subject: [PATCH] Don't free cookies when a redirect sends you back to the same host --- http.c | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/http.c b/http.c index 7359b6e..dc11bd1 100644 --- a/http.c +++ b/http.c @@ -734,31 +734,36 @@ int openconnect_obtain_cookie(struct openconnect_info *vpninfo) /* New host. Tear down the existing connection and make a new one */ char *host = vpninfo->redirect_url + 8; char *path = strchr(host, '/'); + free(vpninfo->urlpath); if (path) { vpninfo->urlpath = strdup(path); *(path++) = 0; } else vpninfo->urlpath = strdup("/"); - free(vpninfo->hostname); - vpninfo->hostname = strdup(host); - free(vpninfo->redirect_url); - vpninfo->redirect_url = NULL; - /* Kill the existing connection, and a new one will happen */ - SSL_free(vpninfo->https_ssl); - vpninfo->https_ssl = NULL; - close(vpninfo->ssl_fd); - vpninfo->ssl_fd = -1; + if (strcmp(vpninfo->hostname, host)) { + free(vpninfo->hostname); + vpninfo->hostname = strdup(host); + + /* Kill the existing connection, and a new one will happen */ + SSL_free(vpninfo->https_ssl); + vpninfo->https_ssl = NULL; + close(vpninfo->ssl_fd); + vpninfo->ssl_fd = -1; - for (opt = vpninfo->cookies; opt; opt = next) { - next = opt->next; + for (opt = vpninfo->cookies; opt; opt = next) { + next = opt->next; - free(opt->option); - free(opt->value); - free(opt); + free(opt->option); + free(opt->value); + free(opt); + } + vpninfo->cookies = NULL; } - vpninfo->cookies = NULL; + free(vpninfo->redirect_url); + vpninfo->redirect_url = NULL; + goto retry; } else if (vpninfo->redirect_url[0] == '/') { /* Absolute redirect within same host */ -- 2.7.4