Received: from eggs.gnu.org ([2001:4830:134:3::10]:54561) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bn8zp-0006IA-JK for qemu-devel@nongnu.org; Thu, 22 Sep 2016 14:45:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bn8zl-0007QA-Jq for qemu-devel@nongnu.org; Thu, 22 Sep 2016 14:45:21 -0400 References: <1474558931-8968-1-git-send-email-kwolf@redhat.com> <1474558931-8968-2-git-send-email-kwolf@redhat.com> From: Eric Blake Message-ID: Date: Thu, 22 Sep 2016 13:45:05 -0500 MIME-Version: 1.0 In-Reply-To: <1474558931-8968-2-git-send-email-kwolf@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="UoUT4u0peBl1IfK1WA9uR6sWdtvvg4sXJ" Subject: Re: [Qemu-devel] [PATCH 1/3] block: Add '-blockdev' command line option List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin Wolf , qemu-block@nongnu.org Cc: armbru@redhat.com, mreitz@redhat.com, berrange@redhat.com, qemu-devel@nongnu.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --UoUT4u0peBl1IfK1WA9uR6sWdtvvg4sXJ From: Eric Blake To: Kevin Wolf , qemu-block@nongnu.org Cc: armbru@redhat.com, mreitz@redhat.com, berrange@redhat.com, qemu-devel@nongnu.org Message-ID: Subject: Re: [PATCH 1/3] block: Add '-blockdev' command line option References: <1474558931-8968-1-git-send-email-kwolf@redhat.com> <1474558931-8968-2-git-send-email-kwolf@redhat.com> In-Reply-To: <1474558931-8968-2-git-send-email-kwolf@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 09/22/2016 10:42 AM, Kevin Wolf wrote: > This is an option that is directly mapped to the blockdev-add QMP > command. It works more or less like -drive, except that it doesn't > create a BlockBackend and doesn't support legacy options. >=20 > This patch adds minimal documentation, the next patches will improve it= =2E >=20 > Signed-off-by: Kevin Wolf > --- > blockdev.c | 12 +++++++++++ > include/sysemu/sysemu.h | 1 + > qemu-options.hx | 12 +++++++++++ > vl.c | 57 +++++++++++++++++++++++++++++++++++++++++= ++++++++ > 4 files changed, 82 insertions(+) >=20 > +static int blockdev_init_func(void *opaque, QemuOpts *opts, Error **er= rp) > +{ > + BlockdevOptions *options; Uninitialized... > + Visitor *v =3D NULL; > + Error *local_err =3D NULL; > + > + QDict *opts_dict =3D qemu_opts_to_qdict(opts, NULL); > + QObject *crumpled =3D qdict_crumple(opts_dict, true, &local_err); > + if (local_err) { > + goto fail; =2E..can fail without initializing it... > + } > + > + v =3D qobject_string_input_visitor_new(crumpled); > + visit_type_BlockdevOptions(v, NULL, &options, &local_err); This is so deceptively simple! It's taken us months to get to this point, but I love the end result. However, =2E..this initializes options, and may result in malloc'd memory... > + if (local_err) { > + goto fail; > + } > + visit_complete(v, opts); > + > + qmp_blockdev_add(options, &local_err); > + if (local_err) { > + goto fail; > + } > + > +fail: > + QDECREF(opts_dict); > + qobject_decref(crumpled); > + > + visit_free(v); > + > + v =3D qapi_dealloc_visitor_new(); > + visit_type_BlockdevOptions(v, NULL, &options, NULL); =2E..this can call the dealloc visitor on uninitialized memory, if we too= k the first goto... > + visit_free(v); > + > + if (local_err) { > + error_propagate(errp, local_err); > + } > + return !!local_err; =2E..and this leaks options if you did not take the first goto. You want NULL initialization, and a qapi_free_BlockdevOptions(options) in here. > +} > + > static int drive_init_func(void *opaque, QemuOpts *opts, Error **errp)= > { > BlockInterfaceType *block_default_type =3D opaque; --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --UoUT4u0peBl1IfK1WA9uR6sWdtvvg4sXJ Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJX5CaxAAoJEKeha0olJ0NqN5IH/2OX33ZCBAWmx1r43Abinoqs wpq1e5nISYYKn1/OdeO1nGKHsCjA+3YlEFeF6gzhP/X0a2zWnok7hXDHUvymmfNZ 4DKZ5TvWICg7kYQw7aiQcfpbEDv0zg1yE9/V+xBEd5UifUHnPS/PQYk12SI+xpu8 ZDsaWH4YO0NLaokX+twJXxPooUHP719ny0lzbCO3ZBqHoMVuHROgVHyGzpO45QFb rnqwAxUonyfvw9ldeSg8XeUZC2C2qWLG4np2Nv3BNL7LX26nY6RVAwHJzZ6KCw9C L9SXQpcJSnB1hhkSc/2WJp1QjTOFmy6gX+rwB/LGr1vBNtXq8YaqFF5LZ27d2oU= =tXB/ -----END PGP SIGNATURE----- --UoUT4u0peBl1IfK1WA9uR6sWdtvvg4sXJ--