From 859ccf007bdd4d35d2aaa0bf33c08c7fedb5bb9f Mon Sep 17 00:00:00 2001 From: James Bursa Date: Wed, 18 Apr 2007 02:52:26 +0000 Subject: Fix null pointer use when a content with no title is in the local history (history_update() was making title null). svn path=/trunk/netsurf/; revision=3256 --- desktop/history_core.c | 52 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 17 deletions(-) (limited to 'desktop/history_core.c') diff --git a/desktop/history_core.c b/desktop/history_core.c index 1a1f19c61..8ebd0bf90 100644 --- a/desktop/history_core.c +++ b/desktop/history_core.c @@ -34,9 +34,9 @@ #define BOTTOM_MARGIN 30 struct history_page { - char *url; /**< Page URL. */ - char *frag_id; /** Fragment identifier */ - char *title; /**< Page title. */ + char *url; /**< Page URL, never 0. */ + char *frag_id; /** Fragment identifier, or 0. */ + char *title; /**< Page title, never 0. */ }; /** A node in the history tree. */ @@ -151,6 +151,9 @@ struct history_entry *history_clone_entry(struct history *history, struct history_entry *prev = NULL; struct history_entry *new_entry; + assert(entry->page.url); + assert(entry->page.title); + /* clone the entry */ new_entry = malloc(sizeof *entry); if (!new_entry) @@ -160,8 +163,7 @@ struct history_entry *history_clone_entry(struct history *history, if (entry->page.frag_id) new_entry->page.frag_id = strdup(entry->page.frag_id); new_entry->page.title = strdup(entry->page.title); - if (((entry->page.url) && (!new_entry->page.url)) || - ((entry->page.title) && (!new_entry->page.title)) || + if (!new_entry->page.url || !new_entry->page.title || ((entry->page.frag_id) && (!new_entry->page.frag_id))) { free(new_entry->page.url); free(new_entry->page.title); @@ -219,19 +221,15 @@ void history_add(struct history *history, struct content *content, /* allocate space */ entry = malloc(sizeof *entry); + res = url_normalize(content->url, &url); if (res != URL_FUNC_OK) { warn_user("NoMemory", 0); return; } -// LOG(("%s => %s : %s", content->url, url, content->title)); -// LOG(("%s", frag_id)); - title = strdup(content->title ? content->title : url); -// LOG(("after strdup")); - if (!entry || !url || !title) { warn_user("NoMemory", 0); free(entry); @@ -289,15 +287,34 @@ void history_add(struct history *history, struct content *content, void history_update(struct history *history, struct content *content) { + char *title; + char *url; + url_func_result res; + if (!history || !history->current || !history->current->bitmap) return; - if (history->current->page.title) - free(history->current->page.title); - if (content->title) - history->current->page.title = strdup(content->title); - else - history->current->page.title = 0; + assert(history->current->page.url); + assert(history->current->page.title); + + if (content->title) { + title = strdup(content->title); + if (!title) { + warn_user("NoMemory", 0); + return; + } + } else { + res = url_normalize(content->url, &url); + if (res != URL_FUNC_OK) { + warn_user("NoMemory", 0); + return; + } + title = url; + } + + assert(title); + free(history->current->page.title); + history->current->page.title = title; thumbnail_create(content, history->current->bitmap, 0); } @@ -576,7 +593,8 @@ bool history_redraw_entry(struct history *history, return false; if (!nsfont_position_in_string(&css_base_style, entry->page.title, - strlen(entry->page.title), WIDTH, &char_offset, &actual_x)) + strlen(entry->page.title), WIDTH, + &char_offset, &actual_x)) return false; if (!plot.text(entry->x, entry->y + HEIGHT + 12, &css_base_style, entry->page.title, char_offset, 0xffffff, c)) -- cgit v1.2.3