From 5c09e63b7c7bbf1edf768ea03a569ccf8e7399dd Mon Sep 17 00:00:00 2001 From: Kevin Wolf Date: Tue, 14 Feb 2012 11:13:31 +0100 Subject: [PATCH 06/99] block/bochs: improve format checking RH-Author: Kevin Wolf 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 RH-Acked-by: Marcelo Tosatti RH-Acked-by: Laszlo Ersek From: Blue Swirl Bugzilla: 783950 Signed-off-by: Blue Swirl (cherry picked from commit ecbe1576b3287e7907b524901063a8117f544e61) --- block/bochs.c | 13 ++++++++++--- 1 files changed, 10 insertions(+), 3 deletions(-) Signed-off-by: Michal Novotny --- 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