From nobody Thu Nov 6 14:29:13 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; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1541517639988319.6763330417914; Tue, 6 Nov 2018 07:20:39 -0800 (PST) Received: from localhost ([::1]:41638 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gK39i-0001ys-Be for importer@patchew.org; Tue, 06 Nov 2018 10:20:38 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35615) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gK33L-0004DP-PK for qemu-devel@nongnu.org; Tue, 06 Nov 2018 10:14:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gK33E-0004mJ-7U for qemu-devel@nongnu.org; Tue, 06 Nov 2018 10:14:03 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:52316) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gK33D-0004AK-Sy for qemu-devel@nongnu.org; Tue, 06 Nov 2018 10:13:56 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1gK32k-0007xE-Uc; Tue, 06 Nov 2018 15:13:26 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Tue, 6 Nov 2018 15:13:20 +0000 Message-Id: <20181106151323.16154-2-peter.maydell@linaro.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181106151323.16154-1-peter.maydell@linaro.org> References: <20181106151323.16154-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PATCH for-3.1 1/4] slirp: Don't pass possibly -1 fd to send() 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" Content-Type: text/plain; charset="utf-8" Coverity complains (CID 1005726) that we might pass -1 as the fd argument to send() in slirp_send(), because we previously checked for "so->s =3D=3D -1 && so->extra". The case of "so->s =3D=3D -1 but so->extra NULL" should not in theory happen, but it is hard to guarantee because various places in the code do so->s =3D qemu_socket(...) and so will end up with so->s =3D=3D -1 on failure, and not all the paths which call that always throw away the socket in that case (eg tcp_fconnect()). So just check specifically for the condition and fail slirp_send(). Signed-off-by: Peter Maydell --- This is to some extent just placating Coverity. --- slirp/slirp.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/slirp/slirp.c b/slirp/slirp.c index 51de41fc021..3c3c03b22f7 100644 --- a/slirp/slirp.c +++ b/slirp/slirp.c @@ -1091,6 +1091,17 @@ ssize_t slirp_send(struct socket *so, const void *bu= f, size_t len, int flags) return len; } =20 + if (so->s =3D=3D -1) { + /* + * This should in theory not happen but it is hard to be + * sure because some code paths will end up with so->s =3D=3D -1 + * on a failure but don't dispose of the struct socket. + * Check specifically, so we don't pass -1 to send(). + */ + errno =3D EBADF; + return -1; + } + return send(so->s, buf, len, flags); } =20 --=20 2.19.1