From c91e9b3458245a4a7b63751016a5b94749746ef0 Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Sat, 25 Oct 2003 22:03:14 +0000 Subject: [project @ 2003-10-25 22:03:14 by jmb] Fix a bug where an infinite loop is entered if the hostname is entered without a trailing '/'. svn path=/import/netsurf/; revision=387 --- desktop/loginlist.c | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) (limited to 'desktop/loginlist.c') diff --git a/desktop/loginlist.c b/desktop/loginlist.c index 08b1822c1..9089ae287 100644 --- a/desktop/loginlist.c +++ b/desktop/loginlist.c @@ -5,14 +5,14 @@ * Copyright 2003 John M Bell */ +//#define NDEBUG + #include #include #include "netsurf/desktop/401login.h" #include "netsurf/utils/log.h" #include "netsurf/utils/utils.h" -#define NDEBUG - void login_list_dump(void); /** @@ -27,7 +27,7 @@ static struct login *loginlist = &login; void login_list_add(char *host, char* logindets) { struct login *nli = xcalloc(1, sizeof(*nli)); - char *temp = xstrdup(host); + char *temp = get_host_from_url(host); char *i; /* Go back to the path base ie strip the document name @@ -35,9 +35,14 @@ void login_list_add(char *host, char* logindets) { * http://www.blah.com/blah/ * This does, however, mean that directories MUST have a '/' at the end */ - if (temp[strlen(temp)-1] != '/') { - i = strrchr(temp, '/'); - temp[(i-temp)+1] = 0; + if (strlen(temp) < strlen(host)) { + + xfree(temp); + temp = xstrdup(host); + if (temp[strlen(temp)-1] != '/') { + i = strrchr(temp, '/'); + temp[(i-temp)+1] = 0; + } } nli->host = xstrdup(temp); @@ -47,7 +52,7 @@ void login_list_add(char *host, char* logindets) { loginlist->prev->next = nli; loginlist->prev = nli; - LOG(("Adding %s : %s", temp, logindets)); + LOG(("Adding %s", temp)); #ifndef NDEBUG login_list_dump(); #endif @@ -61,7 +66,7 @@ struct login *login_list_get(char *host) { struct login *nli; char *temp, *temphost; - char* i; + char *i; if (host == NULL) return NULL; @@ -69,6 +74,11 @@ struct login *login_list_get(char *host) { temphost = get_host_from_url(host); temp = xstrdup(host); + if (strlen(temphost) > strlen(temp)) { + LOG(("here")); + temp = get_host_from_url(host); + } + /* Work backwards through the path, directory at at time. * Finds the closest match. * eg. http://www.blah.com/moo/ matches the url @@ -76,7 +86,7 @@ struct login *login_list_get(char *host) { * This allows multiple realms (and login details) per host. * Only one set of login details per realm are allowed. */ - while (strcasecmp(temp, temphost) != 0) { + do { LOG(("%s, %d", temp, strlen(temp))); @@ -90,14 +100,19 @@ struct login *login_list_get(char *host) { i = strrchr(temp, '/'); - temp[(i-temp)+1] = 0; + if (temp[(i-temp)-1] != '/') /* reached the scheme? */ + temp[(i-temp)+1] = 0; + else { + xfree(temphost); + return NULL; + } if (nli != loginlist) { LOG(("Got %s", nli->host)); xfree(temphost); return nli; } - } + } while (strcasecmp(temp, temphost) != 0); xfree(temphost); return NULL; -- cgit v1.2.3