[libsoup] Fix a crash when resolving URIs with both spaces and non-UTF8 chars
- From: Dan Winship <danw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup] Fix a crash when resolving URIs with both spaces and non-UTF8 chars
- Date: Mon, 13 Sep 2010 19:43:01 +0000 (UTC)
commit 318dae530cf578b35d87dffcc1a03bced2788769
Author: Dan Winship <danw gnome org>
Date: Mon Sep 13 10:31:02 2010 -0400
Fix a crash when resolving URIs with both spaces and non-UTF8 chars
When using "%.*s" in a UTF-8 locale, in at least some cases, glibc
requires that the string not end in something that looks like a
partial UTF-8 character. This seems wrong according to the c99 spec to
me, but regardless, we need to work around it.
https://bugzilla.gnome.org/show_bug.cgi?id=629449
libsoup/soup-uri.c | 28 +++++++++++++++-------------
1 files changed, 15 insertions(+), 13 deletions(-)
---
diff --git a/libsoup/soup-uri.c b/libsoup/soup-uri.c
index e0a9942..fcafa48 100644
--- a/libsoup/soup-uri.c
+++ b/libsoup/soup-uri.c
@@ -290,8 +290,8 @@ soup_uri_new_with_base (SoupURI *base, const char *uri_string)
last = strrchr (base->path, '/');
if (last) {
- newpath = g_strdup_printf ("%.*s/%s",
- (int)(last - base->path),
+ newpath = g_strdup_printf ("%.*s%s",
+ (int)(last + 1 - base->path),
base->path,
uri->path);
} else
@@ -687,17 +687,19 @@ uri_normalized_copy (const char *part, int length,
} while (*s++);
if (fixup && need_fixup) {
- char *tmp, *sp;
- /* This code is lame, but so are people who put
- * unencoded spaces in URLs!
- */
- while ((sp = strchr (normalized, ' '))) {
- tmp = g_strdup_printf ("%.*s%%20%s",
- (int)(sp - normalized),
- normalized, sp + 1);
- g_free (normalized);
- normalized = tmp;
- };
+ GString *fixed;
+ char *sp, *p;
+
+ fixed = g_string_new (NULL);
+ p = normalized;
+ while ((sp = strchr (p, ' '))) {
+ g_string_append_len (fixed, p, sp - p);
+ g_string_append (fixed, "%20");
+ p = sp + 1;
+ }
+ g_string_append (fixed, p);
+ g_free (normalized);
+ normalized = g_string_free (fixed, FALSE);
}
return normalized;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]