From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Cc: patches@linaro.org,
Samuel Thibault <samuel.thibault@ens-lyon.org>,
Jan Kiszka <jan.kiszka@siemens.com>
Subject: [Qemu-devel] [PATCH for-3.1 1/4] slirp: Don't pass possibly -1 fd to send()
Date: Tue, 6 Nov 2018 15:13:20 +0000 [thread overview]
Message-ID: <20181106151323.16154-2-peter.maydell@linaro.org> (raw)
In-Reply-To: <20181106151323.16154-1-peter.maydell@linaro.org>
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 == -1 && so->extra". The case of "so->s == -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 = qemu_socket(...) and so
will end up with so->s == -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 <peter.maydell@linaro.org>
---
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 *buf, size_t len, int flags)
return len;
}
+ if (so->s == -1) {
+ /*
+ * This should in theory not happen but it is hard to be
+ * sure because some code paths will end up with so->s == -1
+ * on a failure but don't dispose of the struct socket.
+ * Check specifically, so we don't pass -1 to send().
+ */
+ errno = EBADF;
+ return -1;
+ }
+
return send(so->s, buf, len, flags);
}
--
2.19.1
next prev parent reply other threads:[~2018-11-06 15:14 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-06 15:13 [Qemu-devel] [PATCH for-3.1 0/4] slirp: fix coverity issues Peter Maydell
2018-11-06 15:13 ` Peter Maydell [this message]
2018-11-06 23:05 ` [Qemu-devel] [PATCH for-3.1 1/4] slirp: Don't pass possibly -1 fd to send() Samuel Thibault
2018-11-06 15:13 ` [Qemu-devel] [PATCH for-3.1 2/4] slirp: Use g_new() to allocate sockets in socreate() Peter Maydell
2018-11-06 23:07 ` Samuel Thibault
2018-11-06 15:13 ` [Qemu-devel] [PATCH for-3.1 3/4] slirp: Remove code that handles socreate() failure Peter Maydell
2018-11-06 23:08 ` Samuel Thibault
2018-11-06 15:13 ` [Qemu-devel] [PATCH for-3.1 4/4] slirp: fork_exec(): create and connect child socket before fork() Peter Maydell
2018-11-06 23:11 ` Samuel Thibault
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181106151323.16154-2-peter.maydell@linaro.org \
--to=peter.maydell@linaro.org \
--cc=jan.kiszka@siemens.com \
--cc=patches@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=samuel.thibault@ens-lyon.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).