libsoup r1260 - in trunk: . libsoup tests
- From: danw svn gnome org
- To: svn-commits-list gnome org
- Subject: libsoup r1260 - in trunk: . libsoup tests
- Date: Fri, 3 Apr 2009 00:45:08 +0000 (UTC)
Author: danw
Date: Fri Apr 3 00:45:08 2009
New Revision: 1260
URL: http://svn.gnome.org/viewvc/libsoup?rev=1260&view=rev
Log:
Bug 577630 - libsoup should ignore broken Content-Type headers
* libsoup/soup-message-headers.c (content_type_setter): Ignore
Content-Type if it's not at least minimally syntactically correct.
(soup_message_headers_get_content_type): Document that.
* tests/header-parsing.c (do_content_type_tests): test it.
Modified:
trunk/ChangeLog
trunk/libsoup/soup-message-headers.c
trunk/tests/header-parsing.c
Modified: trunk/libsoup/soup-message-headers.c
==============================================================================
--- trunk/libsoup/soup-message-headers.c (original)
+++ trunk/libsoup/soup-message-headers.c Fri Apr 3 00:45:08 2009
@@ -1106,8 +1106,15 @@
{
g_free (hdrs->content_type);
if (value) {
- parse_content_foo (hdrs, "Content-Type",
- &hdrs->content_type, NULL);
+ char *content_type, *p;
+
+ parse_content_foo (hdrs, "Content-Type", &content_type, NULL);
+ p = strpbrk (content_type, " /");
+ if (!p || *p != '/' || strpbrk (p + 1, " /")) {
+ g_free (content_type);
+ hdrs->content_type = NULL;
+ } else
+ hdrs->content_type = content_type;
} else
hdrs->content_type = NULL;
}
@@ -1123,8 +1130,8 @@
* are only interested in the content type itself.
*
* Return value: a string with the value of the "Content-Type" header
- * or NULL if @hdrs does not contain that header (in which case
- * * params will be * unchanged, is it has been given).
+ * or NULL if @hdrs does not contain that header or it cannot be
+ * parsed (in which case * params will be unchanged).
*
* Since: 2.26
**/
Modified: trunk/tests/header-parsing.c
==============================================================================
--- trunk/tests/header-parsing.c (original)
+++ trunk/tests/header-parsing.c Fri Apr 3 00:45:08 2009
@@ -882,6 +882,8 @@
#define CONTENT_TYPE_TEST_VALUE "US-ASCII"
#define CONTENT_TYPE_TEST_HEADER "text/plain; charset=\"US-ASCII\""
+#define CONTENT_TYPE_BAD_HEADER "plain text, not text/html"
+
static void
do_content_type_tests (void)
{
@@ -918,10 +920,9 @@
if (!mime_type) {
debug_printf (1, " decoding FAILED!\n could not parse\n");
errors++;
- return;
}
- if (strcmp (mime_type, CONTENT_TYPE_TEST_MIME_TYPE) != 0) {
+ if (mime_type && strcmp (mime_type, CONTENT_TYPE_TEST_MIME_TYPE) != 0) {
debug_printf (1, " decoding FAILED!\n bad returned MIME type: %s\n",
mime_type);
errors++;
@@ -934,6 +935,17 @@
if (params)
g_hash_table_destroy (params);
+
+ soup_message_headers_clear (hdrs);
+ soup_message_headers_append (hdrs, "Content-Type",
+ CONTENT_TYPE_BAD_HEADER);
+ mime_type = soup_message_headers_get_content_type (hdrs, ¶ms);
+ if (mime_type) {
+ debug_printf (1, " Bad content rejection FAILED!\n");
+ errors++;
+ } else
+ debug_printf (1, " Bad content rejection OK\n");
+
soup_message_headers_free (hdrs);
debug_printf (1, "\n");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]