qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
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 3/3] slirp: tcp_listen(): Don't try to close() an fd we never opened
Date: Sat,  4 Feb 2017 23:08:35 +0000	[thread overview]
Message-ID: <1486249715-5513-4-git-send-email-peter.maydell@linaro.org> (raw)
In-Reply-To: <1486249715-5513-1-git-send-email-peter.maydell@linaro.org>

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 <peter.maydell@linaro.org>
---
 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, uint32_t laddr,
 	    (listen(s,1) < 0)) {
 		int tmperrno = errno; /* Don't clobber the real reason we failed */
 
-		close(s);
+                if (s >= 0) {
+                    closesocket(s);
+                }
 		sofree(so);
 		/* Restore the real errno */
 #ifdef _WIN32
-- 
2.1.4

  parent reply	other threads:[~2017-02-04 23:34 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-04 23:08 [Qemu-devel] [PATCH 0/3] slirp: fix 3 easy coverity warnings Peter Maydell
2017-02-04 23:08 ` [Qemu-devel] [PATCH 1/3] slirp: Check qemu_socket() return value in udp_listen() Peter Maydell
2017-02-11  4:15   ` Philippe Mathieu-Daudé
2017-02-04 23:08 ` [Qemu-devel] [PATCH 2/3] slirp: Convert mbufs to use g_malloc() and g_free() Peter Maydell
2017-02-11  4:15   ` Philippe Mathieu-Daudé
2017-02-04 23:08 ` Peter Maydell [this message]
2017-02-11  4:15   ` [Qemu-devel] [PATCH 3/3] slirp: tcp_listen(): Don't try to close() an fd we never opened Philippe Mathieu-Daudé

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=1486249715-5513-4-git-send-email-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).