Fix memory leaks in IDN handling and exclude file:// URIs

This commit is contained in:
Enrico Tröger 2009-02-27 20:59:23 +01:00 committed by Christian Dywan
parent edce7d348b
commit 498232b805

View file

@ -142,8 +142,15 @@ sokoke_idn_to_punycode (gchar* uri)
if ((proto = g_utf8_strchr (uri, -1, ':'))) if ((proto = g_utf8_strchr (uri, -1, ':')))
{ {
gulong offset = g_utf8_pointer_to_offset (uri, proto); gulong offset;
gchar* buffer = g_malloc0 (offset + 1); 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); g_utf8_strncpy (buffer, uri, offset);
proto = buffer; proto = buffer;
} }
@ -156,21 +163,29 @@ sokoke_idn_to_punycode (gchar* uri)
if ((path = g_utf8_strchr (hostname, -1, '/'))) if ((path = g_utf8_strchr (hostname, -1, '/')))
{ {
gulong offset = g_utf8_pointer_to_offset (hostname, path); 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); g_utf8_strncpy (buffer, hostname, offset);
hostname = buffer; hostname = buffer;
} }
} }
else else
hostname = uri; hostname = g_strdup (uri);
if (!(q = stringprep_utf8_to_ucs4 (hostname, -1, NULL))) if (!(q = stringprep_utf8_to_ucs4 (hostname, -1, NULL)))
{
g_free (proto);
g_free (hostname);
return uri; return uri;
}
rc = idna_to_ascii_4z (q, &s, IDNA_ALLOW_UNASSIGNED); rc = idna_to_ascii_4z (q, &s, IDNA_ALLOW_UNASSIGNED);
free (q); free (q);
if (rc != IDNA_SUCCESS) if (rc != IDNA_SUCCESS)
{
g_free (proto);
g_free (hostname);
return uri; return uri;
}
if (proto) if (proto)
{ {