Fix fuse_buf_copy() if already at the end of the buffers
authorMiklos Szeredi <miklos@szeredi.hu>
Mon, 8 Nov 2010 15:06:37 +0000 (16:06 +0100)
committerMiklos Szeredi <mszeredi@suse.cz>
Mon, 8 Nov 2010 15:06:37 +0000 (16:06 +0100)
ChangeLog
lib/buffer.c

index 5ce455c278267ba51dcf847cab9860a1cc159217..6b42706c163b91f1638dd0b9b4bc6cbeb89a8c7d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -16,6 +16,8 @@
        with this option then "fusermount -u" will fail if umount(8)
        doesn't support the --fake and --no-canonicalize options.
 
+       * Fix fuse_buf_copy() if already at the end of the buffers
+
 2010-10-14  Miklos Szeredi <miklos@szeredi.hu>
 
        * Use LTLIBICONV when linking libfuse.  This fixes building against
index 8940edd8e7dacba70a62b6a9ff8b259de4f83f91..0006cbf7d04c6c46c5474547f4a9b7f629977eda 100644 (file)
@@ -232,7 +232,10 @@ static ssize_t fuse_buf_copy_one(const struct fuse_buf *dst, size_t dst_off,
 
 static const struct fuse_buf *fuse_bufvec_current(struct fuse_bufvec *bufv)
 {
-       return &bufv->buf[bufv->idx];
+       if (bufv->idx < bufv->count)
+               return &bufv->buf[bufv->idx];
+       else
+               return NULL;
 }
 
 static int fuse_bufvec_advance(struct fuse_bufvec *bufv, size_t len)
@@ -259,11 +262,18 @@ ssize_t fuse_buf_copy(struct fuse_bufvec *dstv, struct fuse_bufvec *srcv,
        for (;;) {
                const struct fuse_buf *src = fuse_bufvec_current(srcv);
                const struct fuse_buf *dst = fuse_bufvec_current(dstv);
-               size_t src_len = src->size - srcv->off;
-               size_t dst_len = dst->size - dstv->off;
-               size_t len = min_size(src_len, dst_len);
+               size_t src_len;
+               size_t dst_len;
+               size_t len;
                ssize_t res;
 
+               if (src == NULL || dst == NULL)
+                       break;
+
+               src_len = src->size - srcv->off;
+               dst_len = dst->size - dstv->off;
+               len = min_size(src_len, dst_len);
+
                res = fuse_buf_copy_one(dst, dstv->off, src, srcv->off, len, flags);
                if (res < 0) {
                        if (!copied)