[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-stable] [PATCH for-2.0 34/47] dmg: drop broken bdrv_pread() loop
From: |
Stefan Hajnoczi |
Subject: |
[Qemu-stable] [PATCH for-2.0 34/47] dmg: drop broken bdrv_pread() loop |
Date: |
Wed, 26 Mar 2014 13:05:56 +0100 |
It is not necessary to check errno for EINTR and the block layer does
not produce short reads. Therefore we can drop the loop that attempts
to read a compressed chunk.
The loop is buggy because it incorrectly adds the transferred bytes
twice:
do {
ret = bdrv_pread(...);
i += ret;
} while (ret >= 0 && ret + i < s->lengths[chunk]);
Luckily we can drop the loop completely and perform a single
bdrv_pread().
Signed-off-by: Stefan Hajnoczi <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block/dmg.c | 15 ++-------------
1 file changed, 2 insertions(+), 13 deletions(-)
diff --git a/block/dmg.c b/block/dmg.c
index f4f3e8e..1cc5426 100644
--- a/block/dmg.c
+++ b/block/dmg.c
@@ -298,21 +298,10 @@ static inline int dmg_read_chunk(BlockDriverState *bs,
int sector_num)
s->current_chunk = s->n_chunks;
switch (s->types[chunk]) {
case 0x80000005: { /* zlib compressed */
- int i;
-
/* we need to buffer, because only the chunk as whole can be
* inflated. */
- i = 0;
- do {
- ret = bdrv_pread(bs->file, s->offsets[chunk] + i,
- s->compressed_chunk + i,
- s->lengths[chunk] - i);
- if (ret < 0 && errno == EINTR) {
- ret = 0;
- }
- i += ret;
- } while (ret >= 0 && ret + i < s->lengths[chunk]);
-
+ ret = bdrv_pread(bs->file, s->offsets[chunk],
+ s->compressed_chunk, s->lengths[chunk]);
if (ret != s->lengths[chunk]) {
return -1;
}
--
1.8.5.3
- Re: [Qemu-stable] [Qemu-devel] [PATCH for-2.0 39/47] block: vdi bounds check qemu-io tests, (continued)
[Qemu-stable] [PATCH for-2.0 36/47] dmg: sanitize chunk length and sectorcount (CVE-2014-0145), Stefan Hajnoczi, 2014/03/26
[Qemu-stable] [PATCH for-2.0 32/47] dmg: coding style and indentation cleanup, Stefan Hajnoczi, 2014/03/26
[Qemu-stable] [PATCH for-2.0 29/47] qcow2: Fix types in qcow2_alloc_clusters and alloc_clusters_noref, Stefan Hajnoczi, 2014/03/26
[Qemu-stable] [PATCH for-2.0 35/47] dmg: use appropriate types when reading chunks, Stefan Hajnoczi, 2014/03/26
[Qemu-stable] [PATCH for-2.0 34/47] dmg: drop broken bdrv_pread() loop,
Stefan Hajnoczi <=
[Qemu-stable] [PATCH for-2.0 33/47] dmg: prevent out-of-bounds array access on terminator, Stefan Hajnoczi, 2014/03/26