From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47356) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XbsUO-0004Su-FS for qemu-devel@nongnu.org; Wed, 08 Oct 2014 10:45:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XbsUJ-0007GV-VZ for qemu-devel@nongnu.org; Wed, 08 Oct 2014 10:45:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:5354) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XbsUJ-0007GQ-OS for qemu-devel@nongnu.org; Wed, 08 Oct 2014 10:45:11 -0400 Message-ID: <54354DF3.6010108@redhat.com> Date: Wed, 08 Oct 2014 08:45:07 -0600 From: Eric Blake MIME-Version: 1.0 References: <1412770434-6290-1-git-send-email-reftel@spotify.com> <1412770434-6290-2-git-send-email-reftel@spotify.com> In-Reply-To: <1412770434-6290-2-git-send-email-reftel@spotify.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="6sDDrjAKXCFCbxU8D2XTXqanMgOIEnsSB" Subject: Re: [Qemu-devel] [PATCH] linux-user: Let user specify random seed List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Magnus Reftel , qemu-devel@nongnu.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --6sDDrjAKXCFCbxU8D2XTXqanMgOIEnsSB Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 10/08/2014 06:13 AM, Magnus Reftel wrote: > This patch introduces the -seed command line option and the > QEMU_RAND_SEED environment variable for setting the random seed, which > is used for the AT_RANDOM ELF aux entry. >=20 > Signed-off-by: Magnus Reftel > --- > linux-user/elfload.c | 1 - > linux-user/main.c | 21 +++++++++++++++++++++ > 2 files changed, 21 insertions(+), 1 deletion(-) >=20 > +++ b/linux-user/main.c > @@ -46,6 +46,8 @@ unsigned long mmap_min_addr; > #if defined(CONFIG_USE_GUEST_BASE) > unsigned long guest_base; > int have_guest_base; > +static bool have_rand_seed =3D false; static variables are automatically 0-initialized without needing an explicit initializer. > +static int rand_seed; > #if (TARGET_LONG_BITS =3D=3D 32) && (HOST_LONG_BITS =3D=3D 64) > /* > * When running 32-on-64 we should make sure we can fit all of the pos= sible > @@ -3546,6 +3548,12 @@ static void handle_arg_pagesize(const char *arg)= > } > } > =20 > +static void handle_arg_randseed(const char *arg) > +{ > + have_rand_seed =3D true; > + rand_seed =3D atoi(arg); > +} atoi() is trash when compared to strtol() - it doesn't diagnose overflow, trailing garbage, or empty input. > @@ -3926,6 +3936,17 @@ int main(int argc, char **argv, char **envp) > do_strace =3D 1; > } > =20 > + if (getenv("QEMU_RAND_SEED")) { > + have_rand_seed =3D true; > + rand_seed =3D atoi(getenv("QEMU_RAND_SEED")); > + } why not call handle_arg_randseed(getenv("QEMU_RAND_SEED")) here? > + > + if (have_rand_seed) { > + srand(rand_seed); > + } else { > + srand((int)time(NULL)); The cast is pointless. This is C. > + } Do you even need have_rand_seed? Why not just pre-initialize rand_seed=3Dtime(NULL) and then overwrite rand_seed if the environment variable is present? --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --6sDDrjAKXCFCbxU8D2XTXqanMgOIEnsSB 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 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg iQEcBAEBCAAGBQJUNU3zAAoJEKeha0olJ0NqY+8H/A6Lq/NGMh19IbGRkmbXiktD IU0UjbvlvGXg8PgAhuS62mOh04CrXrpHsYMJziO7vfeUvHEkklOfdmRnwyIXMdR3 xSMTxY2t2Ql09Prl8+UnMl1Dx6xWKqbsDTllE4RYHjtaoZIQcnN3OEUCqcY5k6st A4C5H9D207paEnbpx4natUTitBs26y2ZN/+TD0Q3w1Zr7HRMEphHftrepITwEcPw NlHvaebsNHxG43B4R9PMGd9IWAtzkz+QmR6jecRC2erijdB0aMnL6PKhg04l+f5U IinM+YVzsm7A1wSWQrndr8EXOHF1cSjVgr60XSyY4B8ol9SllA7DXzZRD8raycE= =Ot48 -----END PGP SIGNATURE----- --6sDDrjAKXCFCbxU8D2XTXqanMgOIEnsSB--