dump: Fix dump-guest-memory termination and use-after-close
commit08a655be71d0a130a5d9bf7816d096ec31c4f055
authorGonglei <arei.gonglei@huawei.com>
Thu, 30 Oct 2014 06:01:17 +0000 (30 14:01 +0800)
committerMichael Tokarev <mjt@tls.msk.ru>
Sun, 2 Nov 2014 07:04:34 +0000 (2 10:04 +0300)
tree3f4f124270dfb0a5a465c98eeb2b9203127fedfa
parent7d5a8435baed70f03bbe791aba12f5586ba17d75
dump: Fix dump-guest-memory termination and use-after-close

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 <arei.gonglei@huawei.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
dump.c