From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59541) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xyecc-000145-Kw for qemu-devel@nongnu.org; Wed, 10 Dec 2014 05:35:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XyecW-0008RU-HT for qemu-devel@nongnu.org; Wed, 10 Dec 2014 05:35:54 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39633) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XyecV-0008Qw-My for qemu-devel@nongnu.org; Wed, 10 Dec 2014 05:35:48 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id sBAAZl1N007494 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Wed, 10 Dec 2014 05:35:47 -0500 From: Kevin Wolf Date: Wed, 10 Dec 2014 11:34:34 +0100 Message-Id: <1418207679-32260-69-git-send-email-kwolf@redhat.com> In-Reply-To: <1418207679-32260-1-git-send-email-kwolf@redhat.com> References: <1418207679-32260-1-git-send-email-kwolf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL 68/73] vmdk: Use g_random_int to generate CID List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com From: Fam Zheng This replaces two "time(NULL)" invocations with "g_random_int()". According to VMDK spec, CID "is a random 32=E2=80=90bit value updated the= first time the content of the virtual disk is modified after the virtual disk is opened". Using "seconds since epoch" is just a "lame way" to generate it, and not completely safe because of the low precision. Suggested-by: Markus Armbruster Signed-off-by: Fam Zheng Reviewed-by: Markus Armbruster Reviewed-by: Don Koch Reviewed-by: Max Reitz Message-id: 1417649314-13704-2-git-send-email-famz@redhat.com Signed-off-by: Max Reitz Signed-off-by: Kevin Wolf --- block/vmdk.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/block/vmdk.c b/block/vmdk.c index 2cbfd3e..ebb4b70 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -28,6 +28,7 @@ #include "qemu/module.h" #include "migration/migration.h" #include +#include =20 #define VMDK3_MAGIC (('C' << 24) | ('O' << 16) | ('W' << 8) | 'D') #define VMDK4_MAGIC (('K' << 24) | ('D' << 16) | ('M' << 8) | 'V') @@ -1538,7 +1539,7 @@ static int vmdk_write(BlockDriverState *bs, int64_t= sector_num, /* update CID on the first write every time the virtual disk is * opened */ if (!s->cid_updated) { - ret =3D vmdk_write_cid(bs, time(NULL)); + ret =3D vmdk_write_cid(bs, g_random_int()); if (ret < 0) { return ret; } @@ -1922,7 +1923,7 @@ static int vmdk_create(const char *filename, QemuOp= ts *opts, Error **errp) } /* generate descriptor file */ desc =3D g_strdup_printf(desc_template, - (uint32_t)time(NULL), + g_random_int(), parent_cid, fmt, parent_desc_line, --=20 1.8.3.1