From 498232b805b5a6b2c6e2a6dba673cc47e6143184 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrico=20Tr=C3=B6ger?= Date: Fri, 27 Feb 2009 20:59:23 +0100 Subject: [PATCH] Fix memory leaks in IDN handling and exclude file:// URIs --- midori/sokoke.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/midori/sokoke.c b/midori/sokoke.c index c179692a..c073e1fa 100644 --- a/midori/sokoke.c +++ b/midori/sokoke.c @@ -142,8 +142,15 @@ sokoke_idn_to_punycode (gchar* uri) if ((proto = g_utf8_strchr (uri, -1, ':'))) { - gulong offset = g_utf8_pointer_to_offset (uri, proto); - gchar* buffer = g_malloc0 (offset + 1); + gulong offset; + gchar* buffer; + + /* 'file' URIs don't have a hostname */ + if (!strcmp (proto, "file")) + return uri; + + offset = g_utf8_pointer_to_offset (uri, proto); + buffer = g_malloc0 (offset + 1); g_utf8_strncpy (buffer, uri, offset); proto = buffer; } @@ -156,21 +163,29 @@ sokoke_idn_to_punycode (gchar* uri) if ((path = g_utf8_strchr (hostname, -1, '/'))) { gulong offset = g_utf8_pointer_to_offset (hostname, path); - gchar* buffer = g_malloc0 (offset); + gchar* buffer = g_malloc0 (offset + 1); g_utf8_strncpy (buffer, hostname, offset); hostname = buffer; } } else - hostname = uri; + hostname = g_strdup (uri); if (!(q = stringprep_utf8_to_ucs4 (hostname, -1, NULL))) + { + g_free (proto); + g_free (hostname); return uri; + } rc = idna_to_ascii_4z (q, &s, IDNA_ALLOW_UNASSIGNED); free (q); if (rc != IDNA_SUCCESS) + { + g_free (proto); + g_free (hostname); return uri; + } if (proto) {