[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-trivial] [PULL 14/23] dump: Fix dump-guest-memory termination and
From: |
Michael Tokarev |
Subject: |
[Qemu-trivial] [PULL 14/23] dump: Fix dump-guest-memory termination and use-after-close |
Date: |
Sun, 2 Nov 2014 14:57:26 +0300 |
From: Gonglei <address@hidden>
dump_iterate() dumps blocks in a loop. Eventually, get_next_block()
returns "no more". We then call dump_completed(). But we neglect to
break the loop! Broken in commit 4c7e251a.
Because of that, we dump the last block again. This attempts to write
to s->fd, which fails if we're lucky. The error makes dump_iterate()
return failure. It's the only way it can ever return.
Theoretical: if we're not so lucky, something else has opened something
for writing and got the same fd. dump_iterate() then keeps looping,
messing up the something else's output, until a write fails, or the
process mercifully terminates.
The obvious fix is to restore the return lost in commit 4c7e251a. But
the root cause of the bug is needlessly opaque loop control. Replace it
by a clean do ... while loop.
This makes the badly chosen return values of get_next_block() more
visible. Cleaning that up is outside the scope of this bug fix.
Signed-off-by: Gonglei <address@hidden>
Signed-off-by: Markus Armbruster <address@hidden>
Signed-off-by: Michael Tokarev <address@hidden>
---
dump.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/dump.c b/dump.c
index 06a4915..9c7dad8 100644
--- a/dump.c
+++ b/dump.c
@@ -604,10 +604,9 @@ static void dump_iterate(DumpState *s, Error **errp)
{
GuestPhysBlock *block;
int64_t size;
- int ret;
Error *local_err = NULL;
- while (1) {
+ do {
block = s->next_block;
size = block->target_end - block->target_start;
@@ -623,11 +622,9 @@ static void dump_iterate(DumpState *s, Error **errp)
return;
}
- ret = get_next_block(s, block);
- if (ret == 1) {
- dump_completed(s);
- }
- }
+ } while (!get_next_block(s, block));
+
+ dump_completed(s);
}
static void create_vmcore(DumpState *s, Error **errp)
--
1.7.10.4
- [Qemu-trivial] [PULL 09/23] net/slirp: specify logbase for smbd, (continued)
- [Qemu-trivial] [PULL 09/23] net/slirp: specify logbase for smbd, Michael Tokarev, 2014/11/02
- [Qemu-trivial] [PULL 15/23] os-posix: use global daemon_pipe instead of cryptic fds[1], Michael Tokarev, 2014/11/02
- [Qemu-trivial] [PULL 22/23] tap: fix possible fd leak in net_init_tap, Michael Tokarev, 2014/11/02
- [Qemu-trivial] [PULL 13/23] virtio-9p-proxy: improve error messages in connect_namedsocket(), Michael Tokarev, 2014/11/02
- [Qemu-trivial] [PULL 21/23] tap: do not close(fd) in net_init_tap_one, Michael Tokarev, 2014/11/02
- [Qemu-trivial] [PULL 18/23] os-posix: reorder parent notification for -daemonize, Michael Tokarev, 2014/11/02
- [Qemu-trivial] [PULL 10/23] target-tricore: check return value before using it, Michael Tokarev, 2014/11/02
- [Qemu-trivial] [PULL 20/23] target-i386: Remove unused model_features_t struct, Michael Tokarev, 2014/11/02
- [Qemu-trivial] [PULL 19/23] tap_int.h: remove repeating NETWORK_SCRIPT defines, Michael Tokarev, 2014/11/02
- [Qemu-trivial] [PULL 16/23] os-posix: replace goto again with a proper loop, Michael Tokarev, 2014/11/02
- [Qemu-trivial] [PULL 14/23] dump: Fix dump-guest-memory termination and use-after-close,
Michael Tokarev <=
- Re: [Qemu-trivial] [Qemu-devel] [PULL 00/23] Trivial patches for 2014-11-02, Peter Maydell, 2014/11/03