From: David Gibson <david@gibson.dropbear.id.au>
To: peter.maydell@linaro.org
Cc: agraf@suse.de, qemu-ppc@nongnu.org, qemu-devel@nongnu.org,
mdroth@linux.vnet.ibm.com,
David Gibson <david@gibson.dropbear.id.au>
Subject: [Qemu-devel] [PULL 09/17] spapr_nvram: Check return value from blk_getlength()
Date: Tue, 6 Jun 2017 12:51:27 +1000 [thread overview]
Message-ID: <20170606025135.2685-10-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20170606025135.2685-1-david@gibson.dropbear.id.au>
From: Peter Maydell <peter.maydell@linaro.org>
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>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
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,
--
2.9.4
next prev parent reply other threads:[~2017-06-06 2:51 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-06 2:51 [Qemu-devel] [PULL 00/17] ppc-for-2.10 queue 20170606 David Gibson
2017-06-06 2:51 ` [Qemu-devel] [PULL 01/17] migration: remove register_savevm() David Gibson
2017-06-06 17:49 ` Peter Maydell
2017-06-06 22:14 ` Paolo Bonzini
2017-06-07 8:07 ` Juan Quintela
2017-06-06 2:51 ` [Qemu-devel] [PULL 02/17] migration: Mark CPU states dirty before incoming migration/loadvm David Gibson
2017-06-06 2:51 ` [Qemu-devel] [PULL 03/17] spapr: Move DRC RTAS calls into spapr_drc.c David Gibson
2017-06-06 2:51 ` [Qemu-devel] [PULL 04/17] spapr: Abolish DRC get_fdt method David Gibson
2017-06-06 2:51 ` [Qemu-devel] [PULL 05/17] spapr: Abolish DRC set_configured method David Gibson
2017-06-06 2:51 ` [Qemu-devel] [PULL 06/17] spapr: Make DRC get_index and get_type methods into plain functions David Gibson
2017-06-06 2:51 ` [Qemu-devel] [PULL 07/17] target-ppc: Fix openpic timer read register offset David Gibson
2017-06-06 2:51 ` [Qemu-devel] [PULL 08/17] target/ppc: Fixup set_spr error in h_register_process_table David Gibson
2017-06-06 2:51 ` David Gibson [this message]
2017-06-06 2:51 ` [Qemu-devel] [PULL 10/17] ppc/pnv: check the return value of fdt_setprop() David Gibson
2017-06-06 2:51 ` [Qemu-devel] [PULL 11/17] spapr: Allow boot from vhost-*-scsi backends David Gibson
2017-06-06 2:51 ` [Qemu-devel] [PULL 12/17] spapr/drc: don't migrate DRC of cold-plugged CPUs and LMBs David Gibson
2017-06-06 2:51 ` [Qemu-devel] [PULL 13/17] spapr: Introduce DRC subclasses David Gibson
2017-06-06 2:51 ` [Qemu-devel] [PULL 14/17] spapr: Clean up spapr_dr_connector_by_*() David Gibson
2017-06-06 2:51 ` [Qemu-devel] [PULL 15/17] spapr: Move configure-connector state into DRC David Gibson
2017-06-06 2:51 ` [Qemu-devel] [PULL 16/17] spapr: Eliminate spapr_drc_get_type_str() David Gibson
2017-06-06 2:51 ` [Qemu-devel] [PULL 17/17] spapr: Remove some non-useful properties on DRC objects David Gibson
2017-06-06 14:37 ` [Qemu-devel] [PULL 00/17] ppc-for-2.10 queue 20170606 Peter Maydell
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=20170606025135.2685-10-david@gibson.dropbear.id.au \
--to=david@gibson.dropbear.id.au \
--cc=agraf@suse.de \
--cc=mdroth@linux.vnet.ibm.com \
--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).