From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40294) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aQj4D-00083z-Vz for qemu-devel@nongnu.org; Tue, 02 Feb 2016 17:04:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aQj4D-0002ei-3z for qemu-devel@nongnu.org; Tue, 02 Feb 2016 17:04:57 -0500 References: <1CF37786-9AAA-4E5E-B571-DE20E7A463EB@gmail.com> <20160202171606.GM18461@redhat.com> <72A30A67-5846-4835-B8D2-B7F545F76C0B@gmail.com> <20160202173111.GN18461@redhat.com> <70C3852E-1807-419B-9205-F24B5409EABF@gmail.com> <56B10282.1030609@redhat.com> <54A3ED84-6284-48A5-AF16-3B2BE27917C6@gmail.com> From: Eric Blake Message-ID: <56B12802.8010208@redhat.com> Date: Tue, 2 Feb 2016 15:04:50 -0700 MIME-Version: 1.0 In-Reply-To: <54A3ED84-6284-48A5-AF16-3B2BE27917C6@gmail.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="g11WWrD2u162FJUcNHC6AvExn8rVD4Qcp" Subject: Re: [Qemu-devel] ping: [PATCH v13] block/raw-posix.c: Make physical devices usable in QEMU under Mac OS X host List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Programmingkid Cc: Kevin Wolf , qemu-devel qemu-devel , Qemu-block This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --g11WWrD2u162FJUcNHC6AvExn8rVD4Qcp Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 02/02/2016 02:23 PM, Programmingkid wrote: >> And why isn't bsd_path usable for that purpose? >=20 > After trying it out, I found out why bsd_path isn't usable for that pur= pose. It is because the user might try to use a flash drive as the the cd= rom. Say a flash drive is set to /dev/disk2s9. If the user issues the mon= itor command "change ide1-cd0 /dev/disk2s9", this will make "if (strcmp(f= ilename, "/dev/cdrom") =3D=3D 0)" false and bsd_path would never be set. = bsd_path contents would be garbage. >=20 > This would lead to this code not printing the unmounting directions: >=20 > if (strncmp(filename, "/dev/", 5) =3D=3D 0) { > print_unmounting_directions(filename); > return -1; > } >=20 > It looks keeping filename as an character array is best. No, keep filename as a const char * pointer. It's easy to avoid use of uninitialized memory. Try this: const char *filename; char bsd_path[MAXPATHLEN] =3D ""; =2E.. if (strncmp("/dev/cdrom"...) { bsd_path =3D ... } =2E.. if (strncmp("/dev/"...) { print_unmounting_directions(*bsd_path ? bsd_path : filename); --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --g11WWrD2u162FJUcNHC6AvExn8rVD4Qcp 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/ iQEcBAEBCAAGBQJWsSgDAAoJEKeha0olJ0NqXPoIAKLQwKCZ3IuW4P5e4bFwCp9r SHRobVuokTeyyCebZ5SGp8mHCCcLGk0RjElRFP9T4kped22p6j1yQ+cOv2//YlLX jpL4cVMaahu7zEBP094sjMt8bu/p67eeN+PZpz90ND7u4oypW6hvVWTu3VZB3jnK usuuho3dd1h9jNWsXiLRXN6pZr7aVjnInHfmtRiUDkAXJgDhvQYxyi6hPtYOE0/k ZXDy4Wss8kPlO29Kj56vqzj7loPXNN7REmSpHnKEk4WOFfvvxFni40QizNMpx+VM zjS6ijUF4B3CzuYp91af9u/XJfZUPHf5Ox1goCyQFcl0q5fKSlyz0PezcfPaq+U= =pp/V -----END PGP SIGNATURE----- --g11WWrD2u162FJUcNHC6AvExn8rVD4Qcp--