From: "Michael S. Tsirkin" <mst@redhat.com>
To: Gerd Hoffmann <kraxel@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: [Qemu-devel] Re: [PATCH] add VMSTATE_BOOL
Date: Tue, 9 Nov 2010 15:05:30 +0200 [thread overview]
Message-ID: <20101109130530.GD22705@redhat.com> (raw)
In-Reply-To: <4CD93573.7040009@redhat.com>
On Tue, Nov 09, 2010 at 12:50:11PM +0100, Gerd Hoffmann wrote:
> Hi,
>
> >>>>+static int get_bool(QEMUFile *f, void *pv, size_t size)
> >>>>+{
> >>>>+ bool *v = pv;
> >>>>+ *v = qemu_get_byte(f);
> >>>>+ return 0;
>
> >I think we should verify that value is 0 or 1 and fail
> >migration otherwise, to make it more robust.
>
> I still think such a check doesn't belong into the migration code as
> such a bug would exist without migration too. And if anything we
> should check on save not on load, otherwise qemu can write out
> savevm images which it will refuse to load. I wouldn't call this
> "robust".
>
> cheers,
> Gerd
I think we should verify on load: e.g. the image could have
got corrupted. What, exactly, do you want to check on save?
---
savevm: validate bool values on load
We always save 0 or 1 values for booleans. Validate on input to
increase the chance of detecting input corruption.
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
diff --git a/savevm.c b/savevm.c
index 4e49765..da2fdfa 100644
--- a/savevm.c
+++ b/savevm.c
@@ -680,7 +680,12 @@ uint64_t qemu_get_be64(QEMUFile *f)
static int get_bool(QEMUFile *f, void *pv, size_t size)
{
bool *v = pv;
- *v = qemu_get_byte(f);
+ uint8_t b;
+ b = qemu_get_byte(f);
+ if (b != (uint8_t)true && b != (uint8_t)false) {
+ return -EINVAL;
+ }
+ *v = b;
return 0;
}
next prev parent reply other threads:[~2010-11-09 13:05 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-01 14:51 [Qemu-devel] [PATCH] add VMSTATE_BOOL Gerd Hoffmann
2010-11-01 15:08 ` [Qemu-devel] " malc
2010-11-08 17:47 ` Michael S. Tsirkin
2010-11-09 9:23 ` Markus Armbruster
2010-11-09 9:32 ` Paolo Bonzini
2010-11-09 9:37 ` Gerd Hoffmann
2010-11-09 11:34 ` Michael S. Tsirkin
2010-11-09 11:50 ` Gerd Hoffmann
2010-11-09 13:05 ` Michael S. Tsirkin [this message]
2010-11-09 13:28 ` Gerd Hoffmann
2010-11-09 13:37 ` Michael S. Tsirkin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20101109130530.GD22705@redhat.com \
--to=mst@redhat.com \
--cc=kraxel@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.