From nobody Thu Jul 17 11:22:17 2025 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 1486251338413384.0280733178271; Sat, 4 Feb 2017 15:35:38 -0800 (PST) Received: from localhost ([::1]:41214 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ca9rj-0000sH-Qy for importer@patchew.org; Sat, 04 Feb 2017 18:35:35 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40792) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ca9qL-0000Dv-V9 for qemu-devel@nongnu.org; Sat, 04 Feb 2017 18:34:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ca9qG-0000wV-Iu for qemu-devel@nongnu.org; Sat, 04 Feb 2017 18:34:09 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:48424) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ca9qG-0000vE-CY for qemu-devel@nongnu.org; Sat, 04 Feb 2017 18:34:04 -0500 Received: from mnementh.archaic.org.uk ([81.2.115.146]) by orth.archaic.org.uk with esmtp (Exim 4.84_2) (envelope-from ) id 1ca9Rb-0003Uy-DQ; Sat, 04 Feb 2017 23:08:35 +0000 Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1ca9Rb-0001Rm-CR; Sat, 04 Feb 2017 23:08:35 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Sat, 4 Feb 2017 23:08:35 +0000 Message-Id: <1486249715-5513-4-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1486249715-5513-1-git-send-email-peter.maydell@linaro.org> References: <1486249715-5513-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PATCH 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: Samuel Thibault , Jan Kiszka , patches@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 --- slirp/socket.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/slirp/socket.c b/slirp/socket.c index 6c18971..8692772 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.1.4