From: Kevin Wolf Date: Thu, 5 Mar 2015 10:42:25 +0000 (+0000) Subject: qcow2: Fix NULL dereference in qcow2_open() error path (CVE-2014-0146) X-Git-Tag: qemu-xen-4.4.3-rc1~21 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=a796a261032f5864a83ac4c43f0564f18f22c8be;p=qemu-xen.git qcow2: Fix NULL dereference in qcow2_open() error path (CVE-2014-0146) The qcow2 code assumes that s->snapshots is non-NULL if s->nb_snapshots != 0. By having the initialisation of both fields separated in qcow2_open(), any error occuring in between would cause the error path to dereference NULL in qcow2_free_snapshots() if the image had any snapshots. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz Signed-off-by: Stefan Hajnoczi Signed-off-by: Stefano Stabellini --- diff --git a/block/qcow2.c b/block/qcow2.c index 3bf932b06e..f7569684cf 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -436,9 +436,6 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags) s->refcount_table_size = header.refcount_table_clusters << (s->cluster_bits - 3); - s->snapshots_offset = header.snapshots_offset; - s->nb_snapshots = header.nb_snapshots; - /* read the level 1 table */ s->l1_size = header.l1_size; @@ -508,6 +505,10 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags) bs->backing_file[len] = '\0'; } + /* Internal snapshots */ + s->snapshots_offset = header.snapshots_offset; + s->nb_snapshots = header.nb_snapshots; + ret = qcow2_read_snapshots(bs); if (ret < 0) { goto fail;