From: David Gibson <david@gibson.dropbear.id.au>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: qemu-devel@nongnu.org, patches@linaro.org, qemu-ppc@nongnu.org,
Alexander Graf <agraf@suse.de>
Subject: Re: [Qemu-devel] [PATCH] spapr_nvram: Check return value from blk_getlength()
Date: Tue, 6 Jun 2017 09:19:25 +1000 [thread overview]
Message-ID: <20170605231925.GA13397@umbus.fritz.box> (raw)
In-Reply-To: <1496675657-11599-1-git-send-email-peter.maydell@linaro.org>
[-- Attachment #1: Type: text/plain, Size: 1448 bytes --]
On Mon, Jun 05, 2017 at 04:14:17PM +0100, Peter Maydell wrote:
> The blk_getlength() function can return an error value if the
> image size cannot be determined. Check for this rather than
> ploughing on and trying to g_malloc0() a negative number.
> (Spotted by Coverity, CID 1288484.)
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Applied to ppc-for-2.10, thanks.
> ---
> hw/nvram/spapr_nvram.c | 10 +++++++++-
> 1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/hw/nvram/spapr_nvram.c b/hw/nvram/spapr_nvram.c
> index aa5d2c1..bc355a4 100644
> --- a/hw/nvram/spapr_nvram.c
> +++ b/hw/nvram/spapr_nvram.c
> @@ -144,7 +144,15 @@ static void spapr_nvram_realize(VIOsPAPRDevice *dev, Error **errp)
> int ret;
>
> if (nvram->blk) {
> - nvram->size = blk_getlength(nvram->blk);
> + int64_t len = blk_getlength(nvram->blk);
> +
> + if (len < 0) {
> + error_setg_errno(errp, -len,
> + "could not get length of backing image");
> + return;
> + }
> +
> + nvram->size = len;
>
> ret = blk_set_perm(nvram->blk,
> BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE,
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
prev parent reply other threads:[~2017-06-05 23:54 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-05 15:14 [Qemu-devel] [PATCH] spapr_nvram: Check return value from blk_getlength() Peter Maydell
2017-06-05 23:19 ` David Gibson [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=20170605231925.GA13397@umbus.fritz.box \
--to=david@gibson.dropbear.id.au \
--cc=agraf@suse.de \
--cc=patches@linaro.org \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@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).