From nobody Tue Feb 10 04:55:12 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1488120372304793.2045625937054; Sun, 26 Feb 2017 06:46:12 -0800 (PST) Received: from localhost ([::1]:47172 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ci05S-0006s9-WF for importer@patchew.org; Sun, 26 Feb 2017 09:46:11 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56115) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ci03P-0005ey-8i for qemu-devel@nongnu.org; Sun, 26 Feb 2017 09:44:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ci03M-00026E-7M for qemu-devel@nongnu.org; Sun, 26 Feb 2017 09:44:03 -0500 Received: from hera.aquilenet.fr ([141.255.128.1]:51276) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ci03M-00025s-17 for qemu-devel@nongnu.org; Sun, 26 Feb 2017 09:44:00 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id A16EAB47C; Sun, 26 Feb 2017 15:43:58 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Gee5p1a1saVb; Sun, 26 Feb 2017 15:43:58 +0100 (CET) Received: from var.youpi.perso.aquilenet.fr (unknown [IPv6:2a01:cb19:181:c200:3602:86ff:fe2c:6a19]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 39A94B4FB; Sun, 26 Feb 2017 15:43:56 +0100 (CET) Received: from samy by var.youpi.perso.aquilenet.fr with local (Exim 4.88) (envelope-from ) id 1ci03G-0000fA-TD; Sun, 26 Feb 2017 15:43:54 +0100 X-Virus-Scanned: Debian amavisd-new at aquilenet.fr From: Samuel Thibault To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Sun, 26 Feb 2017 15:43:53 +0100 Message-Id: <20170226144353.2502-4-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170226144353.2502-1-samuel.thibault@ens-lyon.org> References: <20170226144353.2502-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 141.255.128.1 Subject: [Qemu-devel] [PULL 3/3] slirp: tcp_listen(): Don't try to close() an fd we never opened X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jan.kiszka@siemens.com, stefanha@redhat.com, Samuel Thibault Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Peter Maydell Coverity points out (CID 1005725) that an error-exit path in tcp_listen() will try to close(s) even if the reason it got there was that the qemu_socket() failed and s was never opened. Not only that, this isn't even the right function to use, because we need closesocket() to do the right thing on Windows. Change to using the right function and only calling it if needed. Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Samuel Thibault --- slirp/socket.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/slirp/socket.c b/slirp/socket.c index 6c18971368..86927722e1 100644 --- a/slirp/socket.c +++ b/slirp/socket.c @@ -713,7 +713,9 @@ tcp_listen(Slirp *slirp, uint32_t haddr, u_int hport, u= int32_t laddr, (listen(s,1) < 0)) { int tmperrno =3D errno; /* Don't clobber the real reason we failed */ =20 - close(s); + if (s >=3D 0) { + closesocket(s); + } sofree(so); /* Restore the real errno */ #ifdef _WIN32 --=20 2.11.0