qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] block: fix null-pointer bug on error case in block commit
@ 2013-01-15 15:47 Jeff Cody
  2013-01-16 11:54 ` Markus Armbruster
  2013-01-16 12:53 ` Stefan Hajnoczi
  0 siblings, 2 replies; 3+ messages in thread
From: Jeff Cody @ 2013-01-15 15:47 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, armbru, stefanha

This is a bug that was caught by a coverity run by Markus.  In
the error case when we errored out to exit_restore_open early in the
function, 'overlay_bs' was still NULL at that point, although it is
used to look up flags and perform a bdrv_reopen().

Move the overlay_bs lookup to where it is needed, and check for NULL
before restoring the flags.  Also get rid of the unneeded parameter
initialization.

Reported-By: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Jeff Cody <jcody@redhat.com>
---
 block/commit.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/block/commit.c b/block/commit.c
index 61ebdba..553447e 100644
--- a/block/commit.c
+++ b/block/commit.c
@@ -65,7 +65,7 @@ static void coroutine_fn commit_run(void *opaque)
     BlockDriverState *active = s->active;
     BlockDriverState *top = s->top;
     BlockDriverState *base = s->base;
-    BlockDriverState *overlay_bs = NULL;
+    BlockDriverState *overlay_bs;
     int64_t sector_num, end;
     int ret = 0;
     int n = 0;
@@ -92,8 +92,6 @@ static void coroutine_fn commit_run(void *opaque)
         }
     }
 
-    overlay_bs = bdrv_find_overlay(active, top);
-
     end = s->common.len >> BDRV_SECTOR_BITS;
     buf = qemu_blockalign(top, COMMIT_BUFFER_SIZE);
 
@@ -156,7 +154,8 @@ exit_restore_reopen:
     if (s->base_flags != bdrv_get_flags(base)) {
         bdrv_reopen(base, s->base_flags, NULL);
     }
-    if (s->orig_overlay_flags != bdrv_get_flags(overlay_bs)) {
+    overlay_bs = bdrv_find_overlay(active, top);
+    if (overlay_bs && s->orig_overlay_flags != bdrv_get_flags(overlay_bs)) {
         bdrv_reopen(overlay_bs, s->orig_overlay_flags, NULL);
     }
 
-- 
1.8.0.2

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] block: fix null-pointer bug on error case in block commit
  2013-01-15 15:47 [Qemu-devel] [PATCH] block: fix null-pointer bug on error case in block commit Jeff Cody
@ 2013-01-16 11:54 ` Markus Armbruster
  2013-01-16 12:53 ` Stefan Hajnoczi
  1 sibling, 0 replies; 3+ messages in thread
From: Markus Armbruster @ 2013-01-16 11:54 UTC (permalink / raw)
  To: Jeff Cody; +Cc: kwolf, qemu-devel, stefanha

Jeff Cody <jcody@redhat.com> writes:

> This is a bug that was caught by a coverity run by Markus.  In
> the error case when we errored out to exit_restore_open early in the
> function, 'overlay_bs' was still NULL at that point, although it is
> used to look up flags and perform a bdrv_reopen().
>
> Move the overlay_bs lookup to where it is needed, and check for NULL
> before restoring the flags.  Also get rid of the unneeded parameter
> initialization.
>
> Reported-By: Markus Armbruster <armbru@redhat.com>
> Signed-off-by: Jeff Cody <jcody@redhat.com>
> ---
>  block/commit.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/block/commit.c b/block/commit.c
> index 61ebdba..553447e 100644
> --- a/block/commit.c
> +++ b/block/commit.c
> @@ -65,7 +65,7 @@ static void coroutine_fn commit_run(void *opaque)
>      BlockDriverState *active = s->active;
>      BlockDriverState *top = s->top;
>      BlockDriverState *base = s->base;
> -    BlockDriverState *overlay_bs = NULL;
> +    BlockDriverState *overlay_bs;
>      int64_t sector_num, end;
>      int ret = 0;
>      int n = 0;
> @@ -92,8 +92,6 @@ static void coroutine_fn commit_run(void *opaque)
>          }
>      }
>  
> -    overlay_bs = bdrv_find_overlay(active, top);
> -
>      end = s->common.len >> BDRV_SECTOR_BITS;
>      buf = qemu_blockalign(top, COMMIT_BUFFER_SIZE);
>  
> @@ -156,7 +154,8 @@ exit_restore_reopen:
>      if (s->base_flags != bdrv_get_flags(base)) {
>          bdrv_reopen(base, s->base_flags, NULL);
>      }
> -    if (s->orig_overlay_flags != bdrv_get_flags(overlay_bs)) {
> +    overlay_bs = bdrv_find_overlay(active, top);
> +    if (overlay_bs && s->orig_overlay_flags != bdrv_get_flags(overlay_bs)) {
>          bdrv_reopen(overlay_bs, s->orig_overlay_flags, NULL);
>      }

The move doesn't change anything in the "no error" case, because we
don't change active, top or the BDS chain connecting them between old
and new location.

Reviewed-by: Markus Armbruster <armbru@redhat.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] block: fix null-pointer bug on error case in block commit
  2013-01-15 15:47 [Qemu-devel] [PATCH] block: fix null-pointer bug on error case in block commit Jeff Cody
  2013-01-16 11:54 ` Markus Armbruster
@ 2013-01-16 12:53 ` Stefan Hajnoczi
  1 sibling, 0 replies; 3+ messages in thread
From: Stefan Hajnoczi @ 2013-01-16 12:53 UTC (permalink / raw)
  To: Jeff Cody; +Cc: kwolf, qemu-devel, armbru

On Tue, Jan 15, 2013 at 10:47:24AM -0500, Jeff Cody wrote:
> This is a bug that was caught by a coverity run by Markus.  In
> the error case when we errored out to exit_restore_open early in the
> function, 'overlay_bs' was still NULL at that point, although it is
> used to look up flags and perform a bdrv_reopen().
> 
> Move the overlay_bs lookup to where it is needed, and check for NULL
> before restoring the flags.  Also get rid of the unneeded parameter
> initialization.
> 
> Reported-By: Markus Armbruster <armbru@redhat.com>
> Signed-off-by: Jeff Cody <jcody@redhat.com>
> ---
>  block/commit.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)

Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block

Stefan

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-01-16 13:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-15 15:47 [Qemu-devel] [PATCH] block: fix null-pointer bug on error case in block commit Jeff Cody
2013-01-16 11:54 ` Markus Armbruster
2013-01-16 12:53 ` Stefan Hajnoczi

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).