All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Tomáš Golembiovský" <tgolembi@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>, Max Reitz <mreitz@redhat.com>,
	Markus Armbruster <armbru@redhat.com>,
	Eric Blake <eblake@redhat.com>,
	"Daniel P . Berrange" <berrange@redhat.com>,
	qemu-block@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v5] raw_bsd: add offset and size options
Date: Tue, 25 Oct 2016 23:37:33 +0200	[thread overview]
Message-ID: <20161025233733.4a0e2a67@fiorina> (raw)
In-Reply-To: <e5caa2b75e9168909aa3951cd3a4928bfed16e20.1477234224.git.tgolembi@redhat.com>

I should test my code more before submitting it to ML. I have found two
bugs in the patch.


On Sun, 23 Oct 2016 16:54:37 +0200
Tomáš Golembiovský <tgolembi@redhat.com> wrote:

> +static int raw_read_options(QDict *options, BlockDriverState *bs,
> +    BDRVRawState *s, Error **errp)
> +{
> +    Error *local_err = NULL;
> +    QemuOpts *opts = NULL;
> +    int64_t real_size = 0;
> +    int ret;
> +
> +    real_size = bdrv_getlength(bs->file->bs);
> +    if (real_size < 0) {
> +        error_setg_errno(errp, -real_size, "Could not get image size");
> +        return real_size;
> +    }
> +
> +    opts = qemu_opts_create(&raw_runtime_opts, NULL, 0, &error_abort);
> +    qemu_opts_absorb_qdict(opts, options, &local_err);
> +    if (local_err) {
> +        error_propagate(errp, local_err);
> +        ret = -EINVAL;
> +        goto end;
> +    }
> +
> +    s->offset = qemu_opt_get_size(opts, "offset", 0);
> +    if (qemu_opt_find(opts, "size") != NULL) {
> +        s->size = qemu_opt_get_size(opts, "size", 0);
> +        s->has_size = true;
> +    } else {
> +        s->has_size = false;
> +        s->size = real_size;

This has to be:

        s->size = real_size - s->offset;

.. to account for the offset. Otherwise the following check will fail.

> +    }
> +
> +    /* Check size and offset */
> +    if (real_size < s->offset || (real_size - s->offset) < s->size) {
> +        error_setg(errp, "The sum of offset (%" PRIu64 ") and size "
> +            "(%" PRIu64 ") has to be smaller or equal to the "
> +            " actual size of the containing file (%" PRId64 ")",
> +            s->offset, s->size, real_size);
> +        ret = -EINVAL;
> +        goto end;
> +    }
> +
> +    /* Make sure size is multiple of BDRV_SECTOR_SIZE to prevent rounding
> +     * up and leaking out of the specified area. */
> +    if (QEMU_IS_ALIGNED(s->size, BDRV_SECTOR_SIZE)) {

The condition has to be negated. Silly mistake made while rewriting the
condition to use QEMU_IS_ALIGNED.

> +        error_setg(errp, "Specified size is not multiple of %llu",
> +            BDRV_SECTOR_SIZE);
> +        ret = -EINVAL;
> +        goto end;
> +    }
> +
> +    ret = 0;
> +
> +end:
> +
> +    qemu_opts_del(opts);
> +
> +    return ret;
> +}
> +

-- 
Tomáš Golembiovský <tgolembi@redhat.com>

  reply	other threads:[~2016-10-25 21:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-23 14:54 [Qemu-devel] [PATCH v5] Add 'offset' and 'size' options Tomáš Golembiovský
2016-10-23 14:54 ` [Qemu-devel] [PATCH v5] raw_bsd: add offset and size options Tomáš Golembiovský
2016-10-25 21:37   ` Tomáš Golembiovský [this message]
2016-10-26  8:13     ` Kevin Wolf

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=20161025233733.4a0e2a67@fiorina \
    --to=tgolembi@redhat.com \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=eblake@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@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 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.