From nobody Wed Nov 5 06:43:55 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.zohomail.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 1499622921530678.4998935977386; Sun, 9 Jul 2017 10:55:21 -0700 (PDT) Received: from localhost ([::1]:36979 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUGQR-00016W-Pa for importer@patchew.org; Sun, 09 Jul 2017 13:55:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58081) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUGPe-0000ec-QT for qemu-devel@nongnu.org; Sun, 09 Jul 2017 13:54:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dUGPb-0002mb-Ov for qemu-devel@nongnu.org; Sun, 09 Jul 2017 13:54:30 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:37500) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dUGPb-0002lb-IE for qemu-devel@nongnu.org; Sun, 09 Jul 2017 13:54:27 -0400 Received: from mnementh.archaic.org.uk ([81.2.115.146]) by orth.archaic.org.uk with esmtp (Exim 4.84_2) (envelope-from ) id 1dUGPW-0000p7-P2; Sun, 09 Jul 2017 18:54:22 +0100 Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1dUGPW-0007rh-Nn; Sun, 09 Jul 2017 18:54:22 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Sun, 9 Jul 2017 18:54:22 +0100 Message-Id: <20170709175422.30185-1-peter.maydell@linaro.org> X-Mailer: git-send-email 2.11.0 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] slirp: fork_exec(): Don't close() a negative number in fork_exec() 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" In a fork_exec() error path we try to closesocket(s) when s might be a negative number because the thing that failed was the qemu_socket() call. Add a guard so we don't do this. (Spotted by Coverity: CID 1005727 issue 1 of 2.) Signed-off-by: Peter Maydell Reviewed-by: Dr. David Alan Gilbert --- Issue 2 of 2 in CID 1005727 is trickier -- we need to move as much as possible of the client-end connect/accept out of the child process and into the parent as possible. I'm not sure if it's safe to do it all in the parent without deadlocking... slirp/misc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/slirp/misc.c b/slirp/misc.c index 88e9d94197..260187b6b6 100644 --- a/slirp/misc.c +++ b/slirp/misc.c @@ -112,7 +112,9 @@ fork_exec(struct socket *so, const char *ex, int do_pty) bind(s, (struct sockaddr *)&addr, addrlen) < 0 || listen(s, 1) < 0) { error_report("Error: inet socket: %s", strerror(errno)); - closesocket(s); + if (s >=3D 0) { + closesocket(s); + } =20 return 0; } --=20 2.11.0