[yelp] Don't segfault on http:// uri's.



commit 78f0d500bae2d95e29d09a1571aff7adf4a830be
Author: Rupert Swarbrick <rswarbrick gmail com>
Date:   Thu Jun 10 00:34:22 2010 +0100

    Don't segfault on http:// uri's.
    
    This was caused by uri's that came out as
    YELP_URI_DOCUMENT_TYPE_EXTERNAL getting a document_uri of NULL. Then
    this got inserted into several hashtables, whose hash function
    required (non-null) strings.
    
    A fix is to use the canonical uri if document_uri is NULL.

 libyelp/yelp-uri.c     |   17 ++++++++++++++++-
 libyelp/yelp-uri.h     |    2 ++
 src/yelp-application.c |    2 +-
 3 files changed, 19 insertions(+), 2 deletions(-)
---
diff --git a/libyelp/yelp-uri.c b/libyelp/yelp-uri.c
index ec5fcce..9735b05 100644
--- a/libyelp/yelp-uri.c
+++ b/libyelp/yelp-uri.c
@@ -309,12 +309,18 @@ resolve_async (YelpUri *uri)
     }
     else if (strchr (priv->res_arg, ':')) {
         priv->tmptype = YELP_URI_DOCUMENT_TYPE_EXTERNAL;
-        priv->fulluri = g_strdup (priv->res_arg);
     }
     else {
         resolve_file_path (uri);
     }
 
+    /* We _always_ want to have a non-null fulluri, so check for it
+     * having been set here and, if we can't think of something
+     * better, set it to res_arg. */
+    if (!priv->fulluri) {
+        priv->fulluri = g_strdup (priv->res_arg);
+    }
+
  done:
     g_idle_add ((GSourceFunc) resolve_final, uri);
 }
@@ -368,6 +374,15 @@ yelp_uri_get_document_uri (YelpUri *uri)
     YelpUriPrivate *priv = GET_PRIV (uri);
     if (priv->doctype == YELP_URI_DOCUMENT_TYPE_UNRESOLVED)
         return NULL;
+
+    /* There's some client code where it makes sense to want a
+     * document uri, whether or not it conforms to a scheme we really
+     * understand. For example, we might want to look up whether the
+     * given page is currently being visited. */
+    if ((!priv->docuri) && priv->fulluri) {
+        return g_strdup (priv->fulluri);
+    }
+
     return g_strdup (priv->docuri);
 }
 
diff --git a/libyelp/yelp-uri.h b/libyelp/yelp-uri.h
index 8161261..13aa73b 100644
--- a/libyelp/yelp-uri.h
+++ b/libyelp/yelp-uri.h
@@ -73,6 +73,8 @@ void                 yelp_uri_resolve            (YelpUri      *uri);
 gboolean             yelp_uri_is_resolved        (YelpUri      *uri);
 YelpUriDocumentType  yelp_uri_get_document_type  (YelpUri      *uri);
 
+/* Both of these functions return a non-null answer, provided that
+ * the uri has been resolved. */
 gchar *              yelp_uri_get_canonical_uri  (YelpUri      *uri);
 gchar *              yelp_uri_get_document_uri   (YelpUri      *uri);
 
diff --git a/src/yelp-application.c b/src/yelp-application.c
index 071e0c1..4ce1ae6 100644
--- a/src/yelp-application.c
+++ b/src/yelp-application.c
@@ -450,7 +450,7 @@ application_uri_resolved (YelpUri             *uri,
 
     doc_uri = yelp_uri_get_document_uri (uri);
 
-    if (data->new)
+    if (data->new || !doc_uri)
         window = NULL;
     else
         window = g_hash_table_lookup (priv->windows_by_document, doc_uri);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]