From: Jeff Cody <jcody@redhat.com>
To: qemu-block@nongnu.org
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v3 1/1] block/sheepdog: fix argument passed to qemu_strtoul()
Date: Wed, 9 Mar 2016 21:35:20 -0500 [thread overview]
Message-ID: <20160310023520.GA27051@localhost.localdomain> (raw)
In-Reply-To: <e56fc50abedd9a112e0683342c8eafda063cd2f9.1456935548.git.jcody@redhat.com>
On Wed, Mar 02, 2016 at 11:24:42AM -0500, Jeff Cody wrote:
> The function qemu_strtoul() reads 'unsigned long' sized data,
> which is larger than uint32_t on 64-bit machines.
>
> Even though the snap_id field in the header is 32-bits, we must
> accomodate the full size in qemu_strtoul().
>
> This patch also adds more meaningful error handling to the
> qemu_strtoul() call, and subsequent results.
>
> Reported-by: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Jeff Cody <jcody@redhat.com>
> ---
> block/sheepdog.c | 11 +++++++----
> 1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/block/sheepdog.c b/block/sheepdog.c
> index 8739acc..87f0027 100644
> --- a/block/sheepdog.c
> +++ b/block/sheepdog.c
> @@ -2543,7 +2543,7 @@ static int sd_snapshot_delete(BlockDriverState *bs,
> const char *name,
> Error **errp)
> {
> - uint32_t snap_id = 0;
> + unsigned long snap_id = 0;
> char snap_tag[SD_MAX_VDI_TAG_LEN];
> Error *local_err = NULL;
> int fd, ret;
> @@ -2565,12 +2565,15 @@ static int sd_snapshot_delete(BlockDriverState *bs,
> memset(buf, 0, sizeof(buf));
> memset(snap_tag, 0, sizeof(snap_tag));
> pstrcpy(buf, SD_MAX_VDI_LEN, s->name);
> - if (qemu_strtoul(snapshot_id, NULL, 10, (unsigned long *)&snap_id)) {
> - return -1;
> + ret = qemu_strtoul(snapshot_id, NULL, 10, &snap_id);
> + if (ret || snap_id > UINT32_MAX) {
> + error_setg(errp, "Invalid snapshot ID: %s",
> + snapshot_id ? snapshot_id : "<null>");
> + return -EINVAL;
> }
>
> if (snap_id) {
> - hdr.snapid = snap_id;
> + hdr.snapid = (uint32_t) snap_id;
> } else {
> pstrcpy(snap_tag, sizeof(snap_tag), snapshot_id);
> pstrcpy(buf + SD_MAX_VDI_LEN, SD_MAX_VDI_TAG_LEN, snap_tag);
> --
> 1.9.3
>
Thanks,
Applied to my block branch:
git://github.com/codyprime/qemu-kvm-jtc.git block
-Jeff
prev parent reply other threads:[~2016-03-10 2:35 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-02 16:24 [Qemu-devel] [PATCH v3 1/1] block/sheepdog: fix argument passed to qemu_strtoul() Jeff Cody
2016-03-02 16:28 ` Max Reitz
2016-03-02 16:30 ` Eric Blake
2016-03-02 16:36 ` Jeff Cody
2016-03-02 16:32 ` Max Reitz
2016-03-02 16:36 ` Jeff Cody
2016-03-03 4:07 ` Hitoshi Mitake
2016-03-03 4:06 ` Hitoshi Mitake
2016-03-10 2:35 ` Jeff Cody [this message]
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=20160310023520.GA27051@localhost.localdomain \
--to=jcody@redhat.com \
--cc=qemu-block@nongnu.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).