summaryrefslogtreecommitdiff
path: root/libsoup/soup-uri.c
diff options
context:
space:
mode:
authorZan Dobersek <zandobersek@gmail.com>2013-03-07 21:23:15 +0100
committerSergio Villar Senin <svillar@igalia.com>2013-03-11 17:08:19 +0100
commitc1c58c9fc79562b0da4ceeeb3fc378407f8b9c85 (patch)
treea85fa722c611a3bb0db7b0edcdaf872abfac85ba /libsoup/soup-uri.c
parent61d321fa2cfb1ffb34a7c9fc151287c271b4cca4 (diff)
downloadlibsoup-c1c58c9fc79562b0da4ceeeb3fc378407f8b9c85.tar.gz
data: URL requests should serve the whole decoded URL
Address the possibility of data: URLs containing null characters when the data request is being performed. The uri_decoded_copy method is enhanced with a third argument, a pointer to an integer that should be set to the length of decoded data when provided. This length is then set as the request's content length. A test checking the correct behavior is added in requester-test. Calls to uri_decoded_copy where the length of the decoded output is not required are adjusted to provide NULL as the third argument.
Diffstat (limited to 'libsoup/soup-uri.c')
-rw-r--r--libsoup/soup-uri.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/libsoup/soup-uri.c b/libsoup/soup-uri.c
index 28b3025c..723e3610 100644
--- a/libsoup/soup-uri.c
+++ b/libsoup/soup-uri.c
@@ -291,14 +291,14 @@ soup_uri_new_with_base (SoupURI *base, const char *uri_string)
colon = strchr (uri_string, ':');
if (colon && colon < at) {
uri->password = uri_decoded_copy (colon + 1,
- at - colon - 1);
+ at - colon - 1, NULL);
} else {
uri->password = NULL;
colon = at;
}
uri->user = uri_decoded_copy (uri_string,
- colon - uri_string);
+ colon - uri_string, NULL);
uri_string = at + 1;
} else
uri->user = uri->password = NULL;
@@ -320,7 +320,7 @@ soup_uri_new_with_base (SoupURI *base, const char *uri_string)
hostend = colon ? colon : path;
}
- uri->host = uri_decoded_copy (uri_string, hostend - uri_string);
+ uri->host = uri_decoded_copy (uri_string, hostend - uri_string, NULL);
if (colon && colon != path - 1) {
char *portend;
@@ -694,7 +694,7 @@ soup_uri_encode (const char *part, const char *escape_extra)
#define HEXCHAR(s) ((XDIGIT (s[1]) << 4) + XDIGIT (s[2]))
char *
-uri_decoded_copy (const char *part, int length)
+uri_decoded_copy (const char *part, int length, int *decoded_length)
{
unsigned char *s, *d;
char *decoded = g_strndup (part, length);
@@ -715,6 +715,9 @@ uri_decoded_copy (const char *part, int length)
*d++ = *s;
} while (*s++);
+ if (decoded_length)
+ *decoded_length = d - (unsigned char *)decoded - 1;
+
return decoded;
}
@@ -735,7 +738,7 @@ soup_uri_decode (const char *part)
{
g_return_val_if_fail (part != NULL, NULL);
- return uri_decoded_copy (part, strlen (part));
+ return uri_decoded_copy (part, strlen (part), NULL);
}
static char *