summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Winship <danw@gnome.org>2010-02-20 12:44:44 -0500
committerDan Winship <danw@gnome.org>2010-02-20 12:44:44 -0500
commit78f5290eec0c12bacef6eb2f9ec28d7f519ae566 (patch)
treec204a32e2ba491bd1387f80b25bfbc38d3163a9a
parent433fd0c645a6e9aadc908fb3e54675a61819e8d2 (diff)
downloadlibsoup-78f5290eec0c12bacef6eb2f9ec28d7f519ae566.tar.gz
[SoupURI] further fixes to CRLF-stripping
The original code mistakenly assumed that strcpy() can take overlapping arguments, but that's not guaranteed. Rewrite to do a single pass over the string rather than potentially multiple strcpy/memmoves. Fixes "make check" on x86_64.
-rw-r--r--libsoup/soup-uri.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/libsoup/soup-uri.c b/libsoup/soup-uri.c
index 77a06531..0e3795d0 100644
--- a/libsoup/soup-uri.c
+++ b/libsoup/soup-uri.c
@@ -157,10 +157,15 @@ soup_uri_new_with_base (SoupURI *base, const char *uri_string)
len = strcspn (uri_string, "\t\n\r");
if (uri_string[len]) {
- char *clean = g_strdup (uri_string), *bad;
+ char *clean = g_malloc (strlen (uri_string + 1)), *d;
+ const char *s;
+
+ for (s = uri_string, d = clean; *s; s++) {
+ if (*s != '\t' && *s != '\n' && *s != '\r')
+ *d++ = *s;
+ }
+ *d = '\0';
- while ((bad = strpbrk (clean, "\t\n\r")))
- strcpy (bad, bad + 1);
uri = soup_uri_new_with_base (base, clean);
g_free (clean);
return uri;