Mailing List Archive

[6872] cherokee/trunk/cherokee/header.c: Better response header parsing.
Revision: 6872
http://svn.cherokee-project.com/changeset/6872
Author: alo
Date: 2011-10-01 11:27:25 +0200 (Sat, 01 Oct 2011)
Log Message:
-----------
Better response header parsing. (Gets rid of one of the 'TODO's).

Modified Paths:
--------------
cherokee/trunk/cherokee/header.c

Modified: cherokee/trunk/cherokee/header.c
===================================================================
--- cherokee/trunk/cherokee/header.c 2011-10-01 09:27:21 UTC (rev 6871)
+++ cherokee/trunk/cherokee/header.c 2011-10-01 09:27:25 UTC (rev 6872)
@@ -211,6 +211,7 @@
char tmp[4];
char *end;
size_t len;
+ int n;
char *line = buf->buf;
char *begin = buf->buf;

@@ -244,9 +245,6 @@
* HTTP/1.0 403 Forbidden
*/
if (unlikely(! cmp_str(begin, "HTTP/1."))) {
- /* TODO: improve parser
- * (if ! "HTTP/" then leave default http_bad_request).
- */
*error_code = http_version_not_supported;
return ret_error;
}
@@ -267,10 +265,24 @@
break;
}

+ /* Skip whites - there must at least one
+ */
+ if (unlikely (CHEROKEE_CHAR_IS_WHITE (begin[8]))) {
+ return ret_error;
+ }
+
+ n = 9;
+ while (CHEROKEE_CHAR_IS_WHITE (begin[n])) {
+ n++;
+ }
+
/* Read the response code
- * TODO: skip spaces properly (usually there is only one blank).
*/
- memcpy (tmp, begin+9, 3);
+ if (unlikely ((begin + n + 3 > end))) {
+ return ret_error;
+ }
+
+ memcpy (tmp, begin+n, 3);
tmp[3] = '\0';

ret = cherokee_atoi (tmp, (int *)&hdr->response);