From: Daniel Carl Date: Mon, 20 May 2019 21:53:59 +0000 (+0200) Subject: Avoid double free in on_webview_notify_uri #561. X-Git-Url: https://git.owens.tech/projects.html/projects.html/git?a=commitdiff_plain;h=333496479192bd995b5dce0384c080c2915c3b20;p=vimb.git Avoid double free in on_webview_notify_uri #561. 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. --- diff --git a/src/main.c b/src/main.c index 2ef2ac7..6a228a1 100644 --- a/src/main.c +++ b/src/main.c @@ -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); diff --git a/src/util.c b/src/util.c index f2dfee7..4cc50a0 100644 --- a/src/util.c +++ b/src/util.c @@ -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. */