mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-28 13:12:10 +01:00
networkaddress: Add early sanity check to _g_uri_parse_authority()
Check whether the URI is valid ASCII before trying to parse it. This should catch broken URIs early. https://bugzilla.gnome.org/show_bug.cgi?id=772989
This commit is contained in:
parent
5f2c20e88b
commit
99b792fac0
@ -492,7 +492,7 @@ _g_uri_parse_authority (const char *uri,
|
|||||||
char **userinfo,
|
char **userinfo,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
char *tmp_str;
|
char *ascii_uri, *tmp_str;
|
||||||
const char *start, *p, *at, *delim;
|
const char *start, *p, *at, *delim;
|
||||||
char c;
|
char c;
|
||||||
|
|
||||||
@ -507,6 +507,11 @@ _g_uri_parse_authority (const char *uri,
|
|||||||
if (userinfo)
|
if (userinfo)
|
||||||
*userinfo = NULL;
|
*userinfo = NULL;
|
||||||
|
|
||||||
|
/* Catch broken URIs early by trying to convert to ASCII. */
|
||||||
|
ascii_uri = g_hostname_to_ascii (uri);
|
||||||
|
if (!ascii_uri)
|
||||||
|
goto error;
|
||||||
|
|
||||||
/* From RFC 3986 Decodes:
|
/* From RFC 3986 Decodes:
|
||||||
* URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
|
* URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
|
||||||
* hier-part = "//" authority path-abempty
|
* hier-part = "//" authority path-abempty
|
||||||
@ -515,7 +520,7 @@ _g_uri_parse_authority (const char *uri,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* Check we have a valid scheme */
|
/* Check we have a valid scheme */
|
||||||
tmp_str = g_uri_parse_scheme (uri);
|
tmp_str = g_uri_parse_scheme (ascii_uri);
|
||||||
|
|
||||||
if (tmp_str == NULL)
|
if (tmp_str == NULL)
|
||||||
goto error;
|
goto error;
|
||||||
@ -525,7 +530,7 @@ _g_uri_parse_authority (const char *uri,
|
|||||||
/* Decode hier-part:
|
/* Decode hier-part:
|
||||||
* hier-part = "//" authority path-abempty
|
* hier-part = "//" authority path-abempty
|
||||||
*/
|
*/
|
||||||
p = uri;
|
p = ascii_uri;
|
||||||
start = strstr (p, "//");
|
start = strstr (p, "//");
|
||||||
|
|
||||||
if (start == NULL)
|
if (start == NULL)
|
||||||
@ -715,6 +720,8 @@ error:
|
|||||||
*userinfo = NULL;
|
*userinfo = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_free (ascii_uri);
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user