kuksugen / mongoose

Automatically exported from code.google.com/p/mongoose
MIT License
0 stars 0 forks source link

mg_read issue if len is smaller than internal conn->buf_size #223

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. POST request with 600 bytes of data
2. use mg_read with 512 bytes buffer
3. 2nd call of mg_read return the buffer from start instead of offset 512

What is the expected output? What do you see instead?
I see a repeated pattern if using mg_read with a small buffer

What version of the product are you using? On what operating system?
version=2.11 
os=linux 64 bits

Please provide any additional information below.
here a patch that fix this issue:

+++ server/mongoose/mongoose.c  (working copy)
@@ -1338,13 +1338,11 @@
     }

     // How many bytes of data we have buffered in the request buffer?
-    buffered = conn->buf + conn->request_len;
-    buffered_len = conn->data_len - conn->request_len;
-    assert(buffered_len >= 0);
+    buffered = conn->buf + conn->request_len + conn->consumed_content;
+    buffered_len = conn->data_len - conn->request_len - conn->consumed_content;

+    if (buffered_len > 0) {
     // Return buffered data back if we haven't done that yet.
-    if (conn->consumed_content < (int64_t) buffered_len) {
-      buffered_len -= (int) conn->consumed_content;
       if (len < (size_t) buffered_len) {
         buffered_len = len;
       }

Original issue reported on code.google.com by laurent....@gmail.com on 24 Jan 2011 at 1:33

GoogleCodeExporter commented 9 years ago
My issue title is not very good: issue occurs when mg_read() is called with a 
buffer size smaller that the bufferized content. Next call to have following 
part will not send the rest of bufferized content, but return same bufferized 
content that first call

Regards,

Laurent

Original comment by laurent....@gmail.com on 24 Jan 2011 at 1:47

GoogleCodeExporter commented 9 years ago

Original comment by valenok on 22 Jun 2011 at 1:21

GoogleCodeExporter commented 9 years ago
This is fixed now, please verify.

Original comment by valenok on 22 Sep 2012 at 2:23