From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:37756) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TO8oY-0007RT-VA for qemu-devel@nongnu.org; Tue, 16 Oct 2012 11:12:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TO8oR-0002i9-J4 for qemu-devel@nongnu.org; Tue, 16 Oct 2012 11:12:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59665) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TO8oR-0002hw-9r for qemu-devel@nongnu.org; Tue, 16 Oct 2012 11:12:07 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9GFC66W028214 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 16 Oct 2012 11:12:06 -0400 Message-ID: <507D7945.3060003@redhat.com> Date: Tue, 16 Oct 2012 09:12:05 -0600 From: Eric Blake MIME-Version: 1.0 References: In-Reply-To: Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="------------enigD743C2F5D614A38495E8F61C" Subject: Re: [Qemu-devel] [PATCH v2 1/4] block: make bdrv_find_backing_image compare canonical filenames List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Jeff Cody Cc: kwolf@redhat.com, qemu-devel@nongnu.org This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigD743C2F5D614A38495E8F61C Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 10/16/2012 08:44 AM, Jeff Cody wrote: > Currently, bdrv_find_backing_image compares bs->backing_file with > what is passed in as a backing_file name. Mismatches may occur, > however, when bs->backing_file and backing_file are both not Reads better as s/both not/not both/. > absolute or relative. >=20 > Use path_combine() to make sure any relative backing filenames are > relative to the current image filename being searched, and then use > realpath() to make all comparisons based on absolute filenames. >=20 > This also changes bdrv_find_backing_image to no longer be recursive, > but iterative. >=20 > Signed-off-by: Jeff Cody > --- > block.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++= +------ > 1 file changed, 58 insertions(+), 6 deletions(-) > - if (!bs->drv) { > + char *filename_full =3D NULL; > + char *backing_file_full =3D NULL; > + char *filename_tmp =3D NULL; > + int is_protocol =3D 0; Any reason you didn't use bool here? > + BlockDriverState *curr_bs =3D NULL; > + BlockDriverState *retval =3D NULL; > + > + if (!bs || !bs->drv || !backing_file) { > return NULL; > } > =20 > - if (bs->backing_hd) { > - if (strcmp(bs->backing_file, backing_file) =3D=3D 0) { > - return bs->backing_hd; > + filename_full =3D g_malloc(sizeof(char) * PATH_MAX); sizeof(char) is guaranteed to be 1; this can be simplified to g_malloc(PATH_MAX). > + backing_file_full =3D g_malloc(sizeof(char) * PATH_MAX); > + filename_tmp =3D g_malloc(sizeof(char) * PATH_MAX); > + if (!filename_full || !backing_file_full || !filename_tmp) { > + goto error; > + } Dead 'if', since g_malloc() is guaranteed to succeed. > + > + is_protocol =3D path_has_protocol(backing_file); > + > + for (curr_bs =3D bs; curr_bs->backing_hd; curr_bs =3D curr_bs->bac= king_hd) { > + > + /* If either of the filename paths is actually a protocol, the= n > + * compare unmodified paths; otherwise make paths relative */ > + if (is_protocol || path_has_protocol(curr_bs->backing_file)) {= > + if (strcmp(backing_file, curr_bs->backing_file) =3D=3D 0) = { I guess we are guaranteed that if is_protocol and path_has_protocol() give different answers, then the strcmp() will fail? --=20 Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --------------enigD743C2F5D614A38495E8F61C Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Mozilla - http://www.enigmail.net/ iQEcBAEBCAAGBQJQfXlFAAoJEKeha0olJ0NqVhUIAJFf+7A739GQsGy4FV7Rp0x9 MLcutQc1Qc+Hd4Gf46lCAqPE8iNV3nv2CGDBCQmuClkD3Q3CBBrR6C3e9VZNFiwF FK7mYEEfl3C/Gm76pUGPGU2paqWcVXAfwIQfy+5yVF9A+r2s0zjW/SCKJoHvUjnq t0Dgbr1IM86dHJcz/8ziqJOgwQzdarXIkr4RfMKN1jmCYXPdEHZVHb+03+HAc/nk ZR3PJtfXdTm3+UcXgydBTsBR6/NN+1p6GXlUzGQY50ogwxRkxe65WwQ27RXppK4n l+wskVZVBOC4CqAXlJmtDWL+t55bpBTmKhBAj7iCc1KM6jq2zMgj1FfaaaeUBfA= =ZJoR -----END PGP SIGNATURE----- --------------enigD743C2F5D614A38495E8F61C--