diff options
author | Peter Maydell | 2017-06-05 17:14:17 +0200 |
---|---|---|
committer | David Gibson | 2017-06-06 01:18:32 +0200 |
commit | 052495178821fdc97b4125a8677c1b68eb458db9 (patch) | |
tree | 7cec3859cf8af0c77d26f8a1bcea97d7f2eeb590 /hw/nvram/spapr_nvram.c | |
parent | target/ppc: Fixup set_spr error in h_register_process_table (diff) | |
download | qemu-052495178821fdc97b4125a8677c1b68eb458db9.tar.gz qemu-052495178821fdc97b4125a8677c1b68eb458db9.tar.xz qemu-052495178821fdc97b4125a8677c1b68eb458db9.zip |
spapr_nvram: Check return value from blk_getlength()
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>
Diffstat (limited to 'hw/nvram/spapr_nvram.c')
-rw-r--r-- | hw/nvram/spapr_nvram.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/hw/nvram/spapr_nvram.c b/hw/nvram/spapr_nvram.c index aa5d2c1f5f..bc355a4348 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, |