tailhook / libwebsite

An HTTP and websocket protocol implementation for libev event loop (UNMAINTAINED, use rust and tk-http crate)
MIT License
39 stars 14 forks source link

End of headers not detected if they come in more than one read() #4

Closed ghost closed 12 years ago

ghost commented 12 years ago

Steps to reproduce: attempt to GET something via telnet.

Patch:

diff --git src/core.c src/core.c
index 7a4271d..bfab215 100644
--- src/core.c
+++ src/core.c
@@ -811,8 +811,8 @@ static int ws_body_slice(ws_request_t *req, int size) {

 static int ws_head_slice(ws_request_t *req, int size) {
     req->bufposition += size;
-    char *e1 = memmem(req->headers_buf, size, "\r\n\r\n", 4);
-    char *e2 = memmem(req->headers_buf, size, "\n\n", 2);
+    char *e1 = memmem(req->headers_buf, req->bufposition, "\r\n\r\n", 4);
+    char *e2 = memmem(req->headers_buf, req->bufposition, "\n\n", 2);
     size_t reallen;
     if(e2 < e1 && e2 || !e1) {
         e1 = e2;