qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Zhang Haoyu" <zhanghy@sangfor.com>
To: qemu-devel <qemu-devel@nongnu.org>
Subject: [Qemu-devel] [patch] qcow2: double free snapshots
Date: Sat, 9 Aug 2014 13:33:20 +0800	[thread overview]
Message-ID: <201408091333190205168@sangfor.com> (raw)

In qcow2_open(), if qcow2_read_snapshots() failed, qcow2_open() -> qcow2_free_snapshots() will be called, NULL snapshots dereference happened.
because qcow2_free_snapshots has been performed before in the fail case of qcow2_read_snapshots().
shown as below callstack,
qcow2_open
|- qcow2_read_snapshots
|-- goto fail;
|-- qcow2_free_snapshots
|- goto fail;
|- qcow2_free_snapshots  /* on this case, NULL snapshots dereference happened.  */

Signed-off-by: Zhang Haoyu <zhanghy@sangfor.com>
---
 block/qcow2-snapshot.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c
index 0aa9def..15c0513 100644
--- a/block/qcow2-snapshot.c
+++ b/block/qcow2-snapshot.c
@@ -31,6 +31,10 @@ void qcow2_free_snapshots(BlockDriverState *bs)
     BDRVQcowState *s = bs->opaque;
     int i;
 
+    if (!s || !s->snapshots) {
+        return;
+    }
+
     for(i = 0; i < s->nb_snapshots; i++) {
         g_free(s->snapshots[i].name);
         g_free(s->snapshots[i].id_str);
-- 
1.9.4.msysgit.0

             reply	other threads:[~2014-08-09  5:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-09  5:33 Zhang Haoyu [this message]
2014-08-11  2:24 ` [Qemu-devel] [patch] qcow2: double free snapshots Gonglei (Arei)
2014-08-11  6:34   ` Zhang Haoyu

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=201408091333190205168@sangfor.com \
    --to=zhanghy@sangfor.com \
    --cc=qemu-devel@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).