[libsoup] Handle spurious CR/LFs between responses
- From: Dan Winship <danw src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [libsoup] Handle spurious CR/LFs between responses
- Date: Mon, 14 Dec 2009 20:43:18 +0000 (UTC)
commit 24baaefe679f7ef3333193f02b3d6a6397ae6b91
Author: Dan Winship <danw gnome org>
Date: Mon Dec 14 15:39:28 2009 -0500
Handle spurious CR/LFs between responses
based on a patch from Alexander V. Butenko.
https://bugzilla.gnome.org/show_bug.cgi?id=602863
libsoup/soup-headers.c | 15 ++++++++++++++-
tests/header-parsing.c | 8 ++++++++
2 files changed, 22 insertions(+), 1 deletions(-)
---
diff --git a/libsoup/soup-headers.c b/libsoup/soup-headers.c
index 465c4f7..9835392 100644
--- a/libsoup/soup-headers.c
+++ b/libsoup/soup-headers.c
@@ -188,10 +188,12 @@ soup_headers_parse_request (const char *str,
/* RFC 2616 4.1 "servers SHOULD ignore any empty line(s)
* received where a Request-Line is expected."
*/
- while (*str == '\r' || *str == '\n') {
+ while ((*str == '\r' || *str == '\n') && len > 0) {
str++;
len--;
}
+ if (!len)
+ return SOUP_STATUS_BAD_REQUEST;
/* RFC 2616 19.3 "[servers] SHOULD accept any amount of SP or
* HT characters between [Request-Line] fields"
@@ -361,6 +363,17 @@ soup_headers_parse_response (const char *str,
g_return_val_if_fail (str && *str, FALSE);
+ /* Workaround for broken servers that send extra line breaks
+ * after a response, which we then see prepended to the next
+ * response on that connection.
+ */
+ while ((*str == '\r' || *str == '\n') && len > 0) {
+ str++;
+ len--;
+ }
+ if (!len)
+ return FALSE;
+
if (!soup_headers_parse (str, len, headers))
return FALSE;
diff --git a/tests/header-parsing.c b/tests/header-parsing.c
index 4c45140..0086b22 100644
--- a/tests/header-parsing.c
+++ b/tests/header-parsing.c
@@ -470,6 +470,14 @@ static struct ResponseTest {
}
},
+ /* qv bug 602863 */
+ { "HTTP 1.1 response with leading line break",
+ "\nHTTP/1.1 200 ok\r\nFoo: bar\r\n", -1,
+ SOUP_HTTP_1_1, SOUP_STATUS_OK, "ok",
+ { { "Foo", "bar" },
+ { NULL } }
+ },
+
/*************************/
/*** INVALID RESPONSES ***/
/*************************/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]