summaryrefslogtreecommitdiff
path: root/libsoup/soup-message-headers.c
diff options
context:
space:
mode:
authorDan Winship <danw@src.gnome.org>2009-04-05 21:53:10 +0000
committerDan Winship <danw@src.gnome.org>2009-04-05 21:53:10 +0000
commit996b1562e7ae05e22ed7207a87951b97647e24ae (patch)
treee885f0559112656d1f28de047b9ff4d3e688b4f3 /libsoup/soup-message-headers.c
parent96eda53a6e77133369c117f2133495ee23d4619a (diff)
downloadlibsoup-996b1562e7ae05e22ed7207a87951b97647e24ae.tar.gz
Don't allow CR/LF in header names or values
* libsoup/soup-message-headers.c (soup_message_headers_append): Don't let the caller create a header with whitespace or ":" in its name, or with CR or LF in its value, since that would result in us generating syntactically invalid headers. svn path=/trunk/; revision=1264
Diffstat (limited to 'libsoup/soup-message-headers.c')
-rw-r--r--libsoup/soup-message-headers.c33
1 files changed, 31 insertions, 2 deletions
diff --git a/libsoup/soup-message-headers.c b/libsoup/soup-message-headers.c
index 8d96dbab..e77c9feb 100644
--- a/libsoup/soup-message-headers.c
+++ b/libsoup/soup-message-headers.c
@@ -146,7 +146,13 @@ soup_message_headers_clear (SoupMessageHeaders *hdrs)
* @name: the header name to add
* @value: the new value of @name
*
- * Appends a new header with name @name and value @value to @hdrs.
+ * Appends a new header with name @name and value @value to @hdrs. (If
+ * there is an existing header with name @name, then this creates a
+ * second one, which is only allowed for list-valued headers; see also
+ * soup_message_headers_replace().)
+ *
+ * The caller is expected to make sure that @name and @value are
+ * syntactically correct.
**/
void
soup_message_headers_append (SoupMessageHeaders *hdrs,
@@ -158,6 +164,25 @@ soup_message_headers_append (SoupMessageHeaders *hdrs,
g_return_if_fail (name != NULL);
g_return_if_fail (value != NULL);
+ /* Setting a syntactically invalid header name or value is
+ * considered to be a programming error. However, it can also
+ * be a security hole, so we want to fail here even if
+ * compiled with G_DISABLE_CHECKS.
+ */
+#ifndef G_DISABLE_CHECKS
+ g_return_if_fail (strpbrk (name, " \t\r\n:") == NULL);
+ g_return_if_fail (strpbrk (value, "\r\n") == NULL);
+#else
+ if (strpbrk (name, " \t\r\n:")) {
+ g_warning ("soup_message_headers_append: Ignoring bad name '%s'", name);
+ return;
+ }
+ if (strpbrk (value, "\r\n")) {
+ g_warning ("soup_message_headers_append: Ignoring bad value '%s'", value);
+ return;
+ }
+#endif
+
header.name = intern_header_name (name, &setter);
header.value = g_strdup (value);
g_array_append_val (hdrs->array, header);
@@ -173,7 +198,11 @@ soup_message_headers_append (SoupMessageHeaders *hdrs,
* @name: the header name to replace
* @value: the new value of @name
*
- * Replaces the value of the header @name in @hdrs with @value.
+ * Replaces the value of the header @name in @hdrs with @value. (See
+ * also soup_message_headers_append().)
+ *
+ * The caller is expected to make sure that @name and @value are
+ * syntactically correct.
**/
void
soup_message_headers_replace (SoupMessageHeaders *hdrs,