From patchwork Wed Mar 19 11:13:44 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Dr. David Alan Gilbert" X-Patchwork-Id: 331682 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 40D962C008F for ; Wed, 19 Mar 2014 22:14:22 +1100 (EST) Received: from localhost ([::1]:39861 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WQERu-0000HO-8T for incoming@patchwork.ozlabs.org; Wed, 19 Mar 2014 07:14:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35897) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WQERY-0000GG-L6 for qemu-devel@nongnu.org; Wed, 19 Mar 2014 07:14:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WQERQ-0004Ps-Of for qemu-devel@nongnu.org; Wed, 19 Mar 2014 07:13:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:2585) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WQERQ-0004Pk-Gi for qemu-devel@nongnu.org; Wed, 19 Mar 2014 07:13:48 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s2JBDkJ5017171 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 19 Mar 2014 07:13:47 -0400 Received: from dgilbert-t530.home.treblig.org (vpn1-6-243.ams2.redhat.com [10.36.6.243]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s2JBDj0N002815; Wed, 19 Mar 2014 07:13:46 -0400 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org Date: Wed, 19 Mar 2014 11:13:44 +0000 Message-Id: <1395227624-20725-1-git-send-email-dgilbert@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: quintela@redhat.com Subject: [Qemu-devel] [PATCH 1/1] Coverity: Fix failure path for qemu_accept in migration 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: "Dr. David Alan Gilbert" Coverity defects 1005733 & 1005734 complain about passing a -ve value to closesocket in the error paths on incoming migration. Stash the error value and print it in the message (previously we gave no indication of the reason for the failure) Signed-off-by: Dr. David Alan Gilbert --- migration-tcp.c | 11 ++++++----- migration-unix.c | 11 ++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/migration-tcp.c b/migration-tcp.c index 782572d..5c96cd3 100644 --- a/migration-tcp.c +++ b/migration-tcp.c @@ -56,19 +56,20 @@ static void tcp_accept_incoming_migration(void *opaque) socklen_t addrlen = sizeof(addr); int s = (intptr_t)opaque; QEMUFile *f; - int c; + int c, err; do { c = qemu_accept(s, (struct sockaddr *)&addr, &addrlen); - } while (c == -1 && socket_error() == EINTR); + err = socket_error(); + } while (c == -1 && err == EINTR); qemu_set_fd_handler2(s, NULL, NULL, NULL, NULL); closesocket(s); DPRINTF("accepted migration\n"); - if (c == -1) { - fprintf(stderr, "could not accept migration connection\n"); - goto out; + if (c < 0) { + fprintf(stderr, "could not accept migration connection (%d)\n", err); + return; } f = qemu_fopen_socket(c, "rb"); diff --git a/migration-unix.c b/migration-unix.c index 651fc5b..e7cf9a2 100644 --- a/migration-unix.c +++ b/migration-unix.c @@ -56,19 +56,20 @@ static void unix_accept_incoming_migration(void *opaque) socklen_t addrlen = sizeof(addr); int s = (intptr_t)opaque; QEMUFile *f; - int c; + int c, err; do { c = qemu_accept(s, (struct sockaddr *)&addr, &addrlen); - } while (c == -1 && errno == EINTR); + err = errno; + } while (c == -1 && err == EINTR); qemu_set_fd_handler2(s, NULL, NULL, NULL, NULL); close(s); DPRINTF("accepted migration\n"); - if (c == -1) { - fprintf(stderr, "could not accept migration connection\n"); - goto out; + if (c < 0) { + fprintf(stderr, "could not accept migration connection (%d)\n", err); + return; } f = qemu_fopen_socket(c, "rb");