[sheepdog] [PATCH 3/3] sheep: fix overflow when reading journal data

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Fri Sep 7 09:45:28 CEST 2012


When writing a whole vdi object, the written data size will be more
than (1 << 22).  This patch allocates the actual data size to read
buffer.

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 sheep/journal.c |   11 ++---------
 1 files changed, 2 insertions(+), 9 deletions(-)

diff --git a/sheep/journal.c b/sheep/journal.c
index e6946e9..a1456c7 100644
--- a/sheep/journal.c
+++ b/sheep/journal.c
@@ -148,19 +148,12 @@ static int jrnl_write_end_mark(struct jrnl_descriptor *jd)
 static int jrnl_apply_to_target_object(struct jrnl_descriptor *jd)
 {
 	char *buf = NULL;
-	int buf_len, res = 0;
+	int res = 0;
 	ssize_t retsize;
 
-	/* FIXME: handle larger size */
-	buf_len = (1 << 22);
-	buf = zalloc(buf_len);
-	if (!buf) {
-		eprintf("failed to allocate memory\n");
-		return SD_RES_NO_MEM;
-	}
-
 	/* Flush out journal to disk (VDI object) */
 	retsize = xpread(jd->fd, &jd->head, sizeof(jd->head), 0);
+	buf = xzalloc(jd->head.size);
 	retsize = xpread(jd->fd, buf, jd->head.size, sizeof(jd->head));
 	retsize = xpwrite(jd->target_fd, buf, jd->head.size, jd->head.offset);
 	if (retsize != jd->head.size) {
-- 
1.7.2.5




More information about the sheepdog mailing list