Avoid double free in on_webview_notify_uri #561.
authorDaniel Carl <danielcarl@gmx.de>
Mon, 20 May 2019 21:53:59 +0000 (23:53 +0200)
committerDaniel Carl <danielcarl@gmx.de>
Mon, 20 May 2019 21:53:59 +0000 (23:53 +0200)
Thank to ValĂ©rian Rousset for pointing this out. Also change the
until_sanitize_uri function to return given uri in case an error occurred
during sanitization process to reduce cases where this function returns
NULL.

src/main.c
src/util.c

index 2ef2ac7..6a228a1 100644 (file)
@@ -1131,7 +1131,7 @@ static void on_webdownload_response_received(WebKitDownload *download,
         GParamSpec *ps, Client *c)
 {
     spawn_download_command(c, webkit_download_get_response(download));
-       webkit_download_cancel(download);
+    webkit_download_cancel(download);
 }
 
 static void spawn_download_command(Client *c, WebKitURIResponse *response)
@@ -1570,11 +1570,8 @@ static void on_webview_notify_uri(WebKitWebView *webview, GParamSpec *pspec, Cli
     if (c->state.uri) {
         g_free(c->state.uri);
     }
-    gchar *url = util_sanitize_uri(webkit_web_view_get_uri(c->webview));
-    if (!url) {
-        return;
-    }
-    c->state.uri = url;
+
+    c->state.uri = util_sanitize_uri(webkit_web_view_get_uri(c->webview));
 
     update_urlbar(c);
     g_setenv("VIMB_URI", c->state.uri, TRUE);
index f2dfee7..4cc50a0 100644 (file)
@@ -834,12 +834,12 @@ char *util_sanitize_uri(const char *uri_str)
     }
 #if WEBKIT_CHECK_VERSION(2, 24, 0)
     for_display = webkit_uri_for_display(uri_str);
+    if (!for_display) {
+        for_display = g_strdup(uri_str);
+    }
 #else
     for_display = g_strdup(uri_str);
 #endif
-    if (!for_display) {
-           return NULL;
-    }
 
     /* Sanitize the uri only in case there is a @ which might be the indicator
      * for credentials used in uri. */