From 07ecaf9e9ed75b5f5898969bad9dd9192179b1ff Mon Sep 17 00:00:00 2001 From: Michael Catanzaro Date: Thu, 14 Dec 2017 11:05:33 -0600 Subject: session: Rework the safety check Tanty and I both lost our Epiphany sessions yesterday... we need to tighten up our URI sanity check. http:/// is a valid SoupURI, but it should never be saved in the session. --- src/ephy-session.c | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/src/ephy-session.c b/src/ephy-session.c index 72a3620e6..53e9dafb3 100644 --- a/src/ephy-session.c +++ b/src/ephy-session.c @@ -822,22 +822,30 @@ save_session_in_thread_finished_cb (GObject *source_object, static gboolean session_seems_sane (GList *windows) { - GList *w; - GList *t; + for (GList *w = windows; w != NULL; w = w->next) { + for (GList *t = ((SessionWindow *)w->data)->tabs; t != NULL; t = t->next) { + const char *url = ((SessionTab *)t->data)->url; + SoupURI *uri; + gboolean sane = FALSE; + + /* Blank URLs can occur in some situations. Just ignore these, as they + * are harmless and not an indicator of a corrupted session. */ + if (strcmp (url, "") == 0) + continue; + + uri = soup_uri_new (url); + if (uri) { + if (uri->host != NULL || + uri->scheme == SOUP_URI_SCHEME_DATA || + uri->scheme == SOUP_URI_SCHEME_FILE) + sane = TRUE; + soup_uri_free (uri); + } - for (w = windows; w != NULL; w = w->next) { - for (t = ((SessionWindow *)w->data)->tabs; t != NULL; t = t->next) { - const char *url = ((SessionTab *)t->data)->url; - SoupURI *uri = soup_uri_new (url); - if (uri) { - soup_uri_free (uri); - } - /* Blank URLs can occur in some situations. Don't save them, but also - * do not torpedo the entire session as it's not a bug. */ - else if (strcmp (url, "") != 0) { - g_critical ("Refusing to save session due to invalid URL %s", url); - return FALSE; - } + if (!sane) { + g_critical ("Refusing to save session due to invalid URL %s", url); + return FALSE; + } } } -- cgit v1.2.1