Patchwork [10/12] block/get_block_status: avoid segfault if there is no backing_hd

login
register
mail settings
Submitter Peter Lieven
Date Sept. 13, 2013, 10:25 a.m.
Message ID <1379067909-22984-11-git-send-email-pl@kamp.de>
Download mbox | patch
Permalink /patch/274719/
State New
Headers show

Comments

Peter Lieven - Sept. 13, 2013, 10:25 a.m.
Signed-off-by: Peter Lieven <pl@kamp.de>
---
 block.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Eric Blake - Sept. 13, 2013, 6:26 p.m.
On 09/13/2013 04:25 AM, Peter Lieven wrote:
> Signed-off-by: Peter Lieven <pl@kamp.de>
> ---
>  block.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Eric Blake <eblake@redhat.com>

> 
> diff --git a/block.c b/block.c
> index 4922fb9..cf9db62 100644
> --- a/block.c
> +++ b/block.c
> @@ -3156,7 +3156,7 @@ static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs,
>      if (!(ret & BDRV_BLOCK_DATA)) {
>          if (bdrv_has_zero_init(bs)) {
>              ret |= BDRV_BLOCK_ZERO;
> -        } else {
> +        } else if (bs->backing_hd) {
>              BlockDriverState *bs2 = bs->backing_hd;
>              int64_t length2 = bdrv_getlength(bs2);
>              if (length2 >= 0 && sector_num >= (length2 >> BDRV_SECTOR_BITS)) {
>

Patch

diff --git a/block.c b/block.c
index 4922fb9..cf9db62 100644
--- a/block.c
+++ b/block.c
@@ -3156,7 +3156,7 @@  static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs,
     if (!(ret & BDRV_BLOCK_DATA)) {
         if (bdrv_has_zero_init(bs)) {
             ret |= BDRV_BLOCK_ZERO;
-        } else {
+        } else if (bs->backing_hd) {
             BlockDriverState *bs2 = bs->backing_hd;
             int64_t length2 = bdrv_getlength(bs2);
             if (length2 >= 0 && sector_num >= (length2 >> BDRV_SECTOR_BITS)) {