Bug fix for sending partial files using ne_set_request_body_fd()
Lou Montulli
lou at montulli.org
Wed Mar 10 20:22:22 EST 2010
I found a bug when using the ne_set_request_body_fd() api and sending only
part of a file.
If the offset+length is less than the total size of the file, then more data
is sent than is requested. This results in a server error due to an
incorrect "Content-Length".
The bug is caused by "body_fd_send()" not decrementing
"req->body.file.remain" after reading from the file. Eventually "read()"
returns "0" when it reaches the end of the file, so this bug doesn't effect
a full file send.
My proposed fix is to decrement "req->body.file.remain" by the number of
bytes read from the file after the "read()" call. This method is
consistent with what "body_string_send()" does.
Diffs are below. I'm happy to rework the code if there are any concerns or
objections.
--- ne_request.c (revision 0.29.3)
+++ ne_request.c (working copy)
@@ -284,6 +284,8 @@
ne_request *req = userdata;
if (count) {
+ size_t read_size = 0;
+
if (req->body.file.remain == 0)
return 0;
@@ -292,7 +294,9 @@
* and 64-bit off64_t: */
if ((ne_off_t)count > req->body.file.remain)
count = (size_t)req->body.file.remain;
- return read(req->body.file.fd, buffer, count);
+ read_size = read(req->body.file.fd, buffer,
count);
+ req->body.file.remain -= read_size;
+ return read_size;
} else {
ne_off_t newoff;
:lou
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.manyfish.co.uk/pipermail/neon/attachments/20100310/3425bb79/attachment.html
More information about the neon
mailing list