From 5c09e63b7c7bbf1edf768ea03a569ccf8e7399dd Mon Sep 17 00:00:00 2001
From: Kevin Wolf <kwolf@redhat.com>
Date: Tue, 14 Feb 2012 11:13:31 +0100
Subject: [PATCH 06/99] block/bochs: improve format checking

RH-Author: Kevin Wolf <kwolf@redhat.com>
Message-id: <1329218101-24213-7-git-send-email-kwolf@redhat.com>
Patchwork-id: 37199
O-Subject: [RHEL-6.3 qemu-kvm PATCH v2 06/96] block/bochs: improve format checking
Bugzilla: 783950
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
RH-Acked-by: Marcelo Tosatti <mtosatti@redhat.com>
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>

From: Blue Swirl <blauwirbel@gmail.com>

Bugzilla: 783950

Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
(cherry picked from commit ecbe1576b3287e7907b524901063a8117f544e61)
---
 block/bochs.c |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)

Signed-off-by: Michal Novotny <minovotn@redhat.com>
---
 block/bochs.c |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/block/bochs.c b/block/bochs.c
index 6df5f49..e952670 100644
--- a/block/bochs.c
+++ b/block/bochs.c
@@ -144,7 +144,9 @@ static int bochs_open(BlockDriverState *bs, const char *filename, int flags)
       bs->total_sectors = le64_to_cpu(bochs.extra.redolog.disk) / 512;
     }
 
-    lseek(s->fd, le32_to_cpu(bochs.header), SEEK_SET);
+    if (lseek(s->fd, le32_to_cpu(bochs.header), SEEK_SET) == (off_t)-1) {
+        goto fail;
+    }
 
     s->catalog_size = le32_to_cpu(bochs.extra.redolog.catalog);
     s->catalog_bitmap = qemu_malloc(s->catalog_size * 4);
@@ -195,7 +197,10 @@ static inline int seek_to_sector(BlockDriverState *bs, int64_t sector_num)
 //	bitmap_offset, block_offset);
 
     // read in bitmap for current extent
-    lseek(s->fd, bitmap_offset + (extent_offset / 8), SEEK_SET);
+    if (lseek(s->fd, bitmap_offset + (extent_offset / 8), SEEK_SET) ==
+        (off_t)-1) {
+        return -1;
+    }
 
     if (read(s->fd, &bitmap_entry, 1) != 1)
         return -1;
@@ -207,7 +212,9 @@ static inline int seek_to_sector(BlockDriverState *bs, int64_t sector_num)
 	return -1; // not allocated
     }
 
-    lseek(s->fd, block_offset, SEEK_SET);
+    if (lseek(s->fd, block_offset, SEEK_SET) == (off_t)-1) {
+        return -1;
+    }
 
     return 0;
 }
-- 
1.7.7.5

