From patchwork Wed Dec 18 16:59:58 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 302997 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 07D7B2C0090 for ; Thu, 19 Dec 2013 04:23:48 +1100 (EST) Received: from localhost ([::1]:39840 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VtKqX-0001Oq-5C for incoming@patchwork.ozlabs.org; Wed, 18 Dec 2013 12:23:45 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34091) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VtKpu-0000zd-5V for qemu-devel@nongnu.org; Wed, 18 Dec 2013 12:23:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VtKpo-00008f-3K for qemu-devel@nongnu.org; Wed, 18 Dec 2013 12:23:06 -0500 Received: from mx1.redhat.com ([209.132.183.28]:4773) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VtKpn-00008B-Sd for qemu-devel@nongnu.org; Wed, 18 Dec 2013 12:23:00 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rBIHMwaU012415 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 18 Dec 2013 12:22:58 -0500 Received: from localhost (ovpn-113-56.phx2.redhat.com [10.3.113.56]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id rBIH0E8R021412; Wed, 18 Dec 2013 12:00:14 -0500 From: Luiz Capitulino To: anthony@codemonkey.ws Date: Wed, 18 Dec 2013 11:59:58 -0500 Message-Id: <1387386003-8949-9-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1387386003-8949-1-git-send-email-lcapitulino@redhat.com> References: <1387386003-8949-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: qemu-devel@nongnu.org Subject: [Qemu-devel] [PULL 08/13] rng: initialize file descriptor to -1 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 Signed-off-by: Luiz Capitulino --- 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 68dfc8a..136499d 100644 --- a/backends/rng-random.c +++ b/backends/rng-random.c @@ -123,15 +123,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); }