From ca3d41cba455fc3a46d9eb03f7a32bd0f2c78532 Mon Sep 17 00:00:00 2001 Message-Id: In-Reply-To: References: From: Amos Kong Date: Tue, 24 Mar 2015 23:00:02 -0500 Subject: [CHANGE 31/33] rng: initialize file descriptor to -1 To: rhvirt-patches@redhat.com, jen@redhat.com RH-Author: Amos Kong Message-id: <1427238004-11205-2-git-send-email-akong@redhat.com> Patchwork-id: 64579 O-Subject: [RHEL-6.7 qemu-kvm PATCH 1/3] rng: initialize file descriptor to -1 Bugzilla: 1119575 RH-Acked-by: Marcel Apfelbaum RH-Acked-by: Amit Shah RH-Acked-by: Paolo Bonzini From: Paolo Bonzini The file descriptor is never initialized to -1, which makes rng-random close stdin if an object is created and immediately destroyed. If we change it to -1, we also need to protect qemu_set_fd_handler from receiving a bogus file descriptor. Signed-off-by: Paolo Bonzini Reviewed-by: Igor Mammedov Tested-by: Igor Mammedov Signed-off-by: Luiz Capitulino (cherry picked from commit 513b8c74c4c899cd940a79131e76c5568aa11381) Signed-off-by: Amos Kong --- backends/rng-random.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) Signed-off-by: Jeff E. Nelson --- backends/rng-random.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backends/rng-random.c b/backends/rng-random.c index a1b92ca..6f617df 100644 --- a/backends/rng-random.c +++ b/backends/rng-random.c @@ -125,15 +125,15 @@ static void rng_random_init(Object *obj) NULL); s->filename = g_strdup("/dev/random"); + s->fd = -1; } static void rng_random_finalize(Object *obj) { RndRandom *s = RNG_RANDOM(obj); - qemu_set_fd_handler(s->fd, NULL, NULL, NULL); - if (s->fd != -1) { + qemu_set_fd_handler(s->fd, NULL, NULL, NULL); qemu_close(s->fd); } -- 2.1.0