Received: from eggs.gnu.org ([2001:4830:134:3::10]:34789) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yq0ol-0001Go-2y for qemu-devel@nongnu.org; Wed, 06 May 2015 11:00:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yq0of-0007Bw-L0 for qemu-devel@nongnu.org; Wed, 06 May 2015 11:00:58 -0400 Date: Wed, 6 May 2015 16:00:50 +0100 From: Stefan Hajnoczi Message-ID: <20150506150050.GE2386@stefanha-thinkpad.redhat.com> References: <65c04848cf88f3342e229464e72d1124ce3d8de9.1430388393.git.berto@igalia.com> <20150501143152.GC2386@stefanha-thinkpad.redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="EgVrEAR5UttbsTXg" Content-Disposition: inline In-Reply-To: Subject: Re: [Qemu-devel] [PATCH 2/6] qcow2: simplify qcow2_cache_put() and qcow2_cache_entry_mark_dirty() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alberto Garcia Cc: Kevin Wolf , Stefan Hajnoczi , qemu-devel@nongnu.org, qemu-block@nongnu.org --EgVrEAR5UttbsTXg Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, May 05, 2015 at 03:06:52PM +0200, Alberto Garcia wrote: > On Fri 01 May 2015 04:31:52 PM CEST, Stefan Hajnoczi wrote: >=20 > >> int qcow2_cache_put(BlockDriverState *bs, Qcow2Cache *c, void **table) > >> { > >> - int i; > >> + int i =3D (*table - c->table_array) / c->table_size; > >> =20 > >> - for (i =3D 0; i < c->size; i++) { > >> - if (table_addr(c, i) =3D=3D *table) { > >> - goto found; > >> - } > >> + if (c->entries[i].offset =3D=3D 0) { > >> + return -ENOENT; > >> } > >> - return -ENOENT; > >> =20 > >> -found: > >> c->entries[i].ref--; > >> *table =3D NULL; > >> =20 > > > > When is this function called with a bogus table pointer? >=20 > I also could not image any such scenario, but I decided to be > conservative and keep the error handling code. I'll double check all > places where it's used and remove the relevant code. The reason why I'd think this is worth looking into is: The new qcow2_cache_put() code indexes outside the array bounds if table is a bogus value. The old code would return -ENOENT. So I am a little nervous about the change, although I suspect the function is never called with invalid inputs at all. Stefan --EgVrEAR5UttbsTXg Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAEBAgAGBQJVSiyiAAoJEJykq7OBq3PIJeoH/3qXRUNpzHsTv39gAxzfkI3h h81wTB1R0g+zKGwW245ZfjbzWakOnr8pJVIRkqpH0ztVal0W9aSGm8jKKEU8KsbS viw23WUpj20BdrObQNlkDVRDPN8LcSCoU34vHW9nijFN7HUarC7jlXBFRDbSaUNk 2brxKKYACKW4OwGjq2KvX3ZA15xnYVstB0EkJ5/sbRSuDsPBAAwKP+P6XzsapWb7 8DT4Y4y9M+63fM9CSfXaU7JwjBsc7hrhY3cubhSOJb+CfLJmbpNEPyKqnplWDKk2 fTLhCrtGWHXBjsCjMniOv5vGxMDRYa+R7Kd66HFwNeIWX3zRB6ID55C+cMIB0Zk= =8Q0h -----END PGP SIGNATURE----- --EgVrEAR5UttbsTXg--