- Define _FILE_OFFSET_BITS

- Use uint64_t to hold object length and buffer length

- Don't pass too much buffer to writev. writev returns -1 if the sum of
  the iov_len values overflows an ssize_t value

Signed-off-by: Akinobu Mita <[email protected]>
---
 server/be-fs.c  |    1 +
 server/chunkd.h |    6 +++---
 server/object.c |    2 +-
 server/server.c |    9 ++++++++-
 4 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/server/be-fs.c b/server/be-fs.c
index 512e33f..a2b23d3 100644
--- a/server/be-fs.c
+++ b/server/be-fs.c
@@ -18,6 +18,7 @@
  */
 
 #define _GNU_SOURCE
+#define _FILE_OFFSET_BITS 64
 #include "chunkd-config.h"
 
 #include <sys/types.h>
diff --git a/server/chunkd.h b/server/chunkd.h
index a97088d..9b3eeb9 100644
--- a/server/chunkd.h
+++ b/server/chunkd.h
@@ -67,7 +67,7 @@ struct timer {
 
 struct client_write {
        const void              *buf;           /* write buffer */
-       int                     len;            /* write buffer length */
+       uint64_t                len;            /* write buffer length */
        cli_write_func          cb;             /* callback */
        void                    *cb_data;       /* data passed to cb */
        bool                    sendfile;       /* using sendfile? */
@@ -115,11 +115,11 @@ struct client {
 
        char                    *out_user;
        SHA_CTX                 out_hash;
-       long                    out_len;
+       uint64_t                out_len;
 
        struct backend_obj      *out_bo;
 
-       long                    in_len;
+       uint64_t                in_len;
        struct backend_obj      *in_obj;
 
        /* we put the big arrays and objects at the end... */
diff --git a/server/object.c b/server/object.c
index a1205f5..ad1d98a 100644
--- a/server/object.c
+++ b/server/object.c
@@ -140,7 +140,7 @@ bool cli_evt_data_in(struct client *cli, unsigned int 
events)
        read_sz = MIN(cli->out_len, CLI_DATA_BUF_SZ);
 
        if (debugging)
-               applog(LOG_DEBUG, "REQ(data-in) seq %x, out_len %ld, read_sz 
%u",
+               applog(LOG_DEBUG, "REQ(data-in) seq %x, out_len %llu, read_sz 
%u",
                       cli->creq.nonce, cli->out_len, read_sz);
 
        if (cli->ssl) {
diff --git a/server/server.c b/server/server.c
index 3f38cca..b04178b 100644
--- a/server/server.c
+++ b/server/server.c
@@ -413,14 +413,21 @@ static int cli_wr_iov(struct client *cli, struct iovec 
*iov, int max_iov)
 {
        struct client_write *tmp;
        int n_iov = 0;
+       ssize_t total =  0;
 
        /* accumulate pending writes into iovec */
        list_for_each_entry(tmp, &cli->write_q, node) {
                if (n_iov >= max_iov)
                        break;
 
+               if (tmp->len > (sizeof(ssize_t) == 8 ? LONG_MAX : INT_MAX))
+                       break;
+               if (total + tmp->len < total)
+                       break;
+
                iov[n_iov].iov_base = (void *) tmp->buf;
                iov[n_iov].iov_len = tmp->len;
+               total += tmp->len;
 
                n_iov++;
        }
@@ -436,7 +443,7 @@ static void cli_wr_completed(struct client *cli, ssize_t 
rc, bool *more_work)
         * amount of data written
         */
        while (rc > 0) {
-               int sz;
+               ssize_t sz;
 
                /* get pointer to first record on list */
                tmp = list_entry(cli->write_q.next, struct client_write, node);
-- 
1.6.0.6

--
To unsubscribe from this list: send the line "unsubscribe hail-devel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to