Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Cherokee: commits
[3423] cherokee/trunk/cherokee: Improves header parsing.
 

Index | Next | Previous | View Flat


cherokee at cherokee-project

Jul 3, 2009, 7:45 AM


Views: 133
Permalink
[3423] cherokee/trunk/cherokee: Improves header parsing.

Revision: 3423
http://svn.cherokee-project.com/changeset/3423
Author: alo
Date: 2009-07-03 16:45:20 +0200 (Fri, 03 Jul 2009)

Log Message:
-----------
Improves header parsing.

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

Modified: cherokee/trunk/cherokee/header.c
===================================================================
--- cherokee/trunk/cherokee/header.c 2009-07-03 13:20:21 UTC (rev 3422)
+++ cherokee/trunk/cherokee/header.c 2009-07-03 14:45:20 UTC (rev 3423)
@@ -722,6 +722,7 @@
static ret_t
has_header_request (cherokee_header_t *hdr, cherokee_buffer_t *buffer, cuint_t tail_len)
{
+ ret_t ret;
char *start;
char *end;
size_t crlf_len = 0;
@@ -744,7 +745,7 @@
* buffer length so we have to move the real content
* to the beginning of the buffer.
*/
- cherokee_buffer_move_to_begin(buffer, (int) crlf_len);
+ cherokee_buffer_move_to_begin (buffer, (int) crlf_len);
}

/* Do we have enough information ?
@@ -763,20 +764,15 @@

/* It could be a partial header, or maybe a POST request
*/
- if (unlikely ((end = strstr(start, CRLF_CRLF)) == NULL)) {
- if ((end = strstr (start, LF_LF)) == NULL)
- return ret_not_found;
-
- /* Found uncommon / non standard EOH, set header length
- */
- hdr->input_header_len = ((int) (end - buffer->buf)) + CSZLEN(LF_LF);
- return ret_ok;
+ ret = cherokee_find_header_end_cstr (start,
+ (buffer->buf + buffer->len) - start,
+ &end, &crlf_len);
+ if (ret != ret_ok) {
+ return ret_not_found;
}
-
- /* Found standard EOH, set header length
- */
- hdr->input_header_len = ((int) (end - buffer->buf)) + CSZLEN(CRLF_CRLF);
-
+
+ hdr->input_header_len = ((int) (end - buffer->buf)) + crlf_len;
+
return ret_ok;
}


Modified: cherokee/trunk/cherokee/util.c
===================================================================
--- cherokee/trunk/cherokee/util.c 2009-07-03 13:20:21 UTC (rev 3422)
+++ cherokee/trunk/cherokee/util.c 2009-07-03 14:45:20 UTC (rev 3423)
@@ -1582,48 +1582,63 @@


ret_t
-cherokee_find_header_end (cherokee_buffer_t *buf,
- char **end,
- cuint_t *sep_len)
+cherokee_find_header_end_cstr (char *c_str,
+ cint_t c_len,
+ char **end,
+ cuint_t *sep_len)
{
char *p;
char *fin;
char *begin;
- char *limit;
- int len;
+ int cr_n, lf_n;

- if (cherokee_buffer_is_empty (buf))
+ if ((c_str == NULL) || (c_len <= 0))
return ret_not_found;

- p = buf->buf;
- fin = buf->buf + buf->len;
- limit = buf->buf + MAX_HEADER_LEN;
+ p = c_str;
+ fin = c_str + MIN(c_len, MAX_HEADER_LEN);

while (p < fin) {
- if (unlikely (p > limit)) {
- return ret_error;
- }
+ if ((*p == CHR_CR) || (*p == CHR_LF)) {
+ cr_n = 0;
+ lf_n = 0;
+ begin = p;

- if ((*p == CHR_CR) || (*p == CHR_LF)) {
- len = 0;
- begin = p;
- while ((*p == CHR_CR) || (*p == CHR_LF)) {
+ /* Valid scenarios:
+ * CR_n: [CRLF_CRLF] 0, 1, 1, 2, 2 | [LF_LF] 0, 0
+ * LF_n: 0, 0, 1, 1, 2 | 1, 2
+ *
+ * so, the two forbidden situations are:
+ * CR_n: 1, 2
+ * LF_n: 2, 0
+ */
+ while (p < fin) {
if (*p == CHR_LF) {
- len += 1;
- if (len == 2) {
+ lf_n++;
+ if (lf_n == 2) {
*end = begin;
*sep_len = (p - begin) + 1;
return ret_ok;
}
+
} else if (*p == CHR_CR) {
- ;
+ cr_n++;
+
} else {
break;
}
- p += 1;
+
+ if (unlikely (((cr_n == 1) && (lf_n == 2)) ||
+ ((cr_n == 2) && (lf_n == 0))))
+ {
+ return ret_error;
+ }
+
+ p++;
}
}
- p += 1;
+
+ p++;
}

return ret_not_found;
@@ -1631,6 +1646,15 @@


ret_t
+cherokee_find_header_end (cherokee_buffer_t *buf,
+ char **end,
+ cuint_t *sep_len)
+{
+ return cherokee_find_header_end_cstr (buf->buf, buf->len, end, sep_len);
+}
+
+
+ret_t
cherokee_ntop (int family, struct sockaddr *addr, char *dst, size_t cnt)
{
const char *str = NULL;

Modified: cherokee/trunk/cherokee/util.h
===================================================================
--- cherokee/trunk/cherokee/util.h 2009-07-03 13:20:21 UTC (rev 3422)
+++ cherokee/trunk/cherokee/util.h 2009-07-03 14:45:20 UTC (rev 3423)
@@ -113,6 +113,11 @@
char **end,
cuint_t *sep_len);

+ret_t cherokee_find_header_end_cstr (char *c_str,
+ cint_t c_len,
+ char **end,
+ cuint_t *sep_len);
+
ret_t cherokee_parse_host (cherokee_buffer_t *buf,
cherokee_buffer_t *host,
cuint_t *port);

Subject User Time
[3423] cherokee/trunk/cherokee: Improves header parsing. cherokee at cherokee-project Jul 3, 2009, 7:45 AM

  Index | Next | Previous | View Flat
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.