[Sheepdog] [PATCH 4/5] collie vdi write: do not try to write beyond end of vdi

Chris Webb chris at arachsys.com
Sat Aug 13 12:56:21 CEST 2011


Signed-off-by: Chris Webb <chris at arachsys.com>
---
 collie/vdi.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/collie/vdi.c b/collie/vdi.c
index 6b2f26c..ef386ea 100644
--- a/collie/vdi.c
+++ b/collie/vdi.c
@@ -1097,8 +1097,15 @@ static int vdi_write(int argc, char **argv)
 		goto out;
 	}
 
+	if (inode->vdi_size < offset) {
+		fprintf(stderr, "offset beyond end of vdi\n");
+		ret = EXIT_FAILURE;
+		goto out;
+	}
+
+	total = min(total, inode->vdi_size - offset);
 	idx = offset / SD_DATA_OBJ_SIZE;
-	while (done != total) {
+	while (done < total) {
 		create = 0;
 		old_oid = 0;
 		flags = 0;
-- 
1.7.5.4




More information about the sheepdog mailing list