All of lore.kernel.org
 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 2/2] slirp: Handle error returns from sosendoob()
Date: Mon,  5 Jun 2017 17:19:36 +0100	[thread overview]
Message-ID: <1496679576-14336-3-git-send-email-peter.maydell@linaro.org> (raw)
In-Reply-To: <1496679576-14336-1-git-send-email-peter.maydell@linaro.org>

sosendoob() can return a failure code, but all its callers ignore it.
This is OK in sbappend(), as the comment there states -- we will try
again later in sowrite(). Add a (void) cast to tell Coverity so.
In sowrite() we do need to check the return value -- we should handle
a write failure in sosendoob() the same way we handle a write failure
for the normal data.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 slirp/sbuf.c   |  2 +-
 slirp/socket.c | 22 ++++++++++++++++------
 2 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/slirp/sbuf.c b/slirp/sbuf.c
index 10119d3..912f235 100644
--- a/slirp/sbuf.c
+++ b/slirp/sbuf.c
@@ -91,7 +91,7 @@ sbappend(struct socket *so, struct mbuf *m)
 	if (so->so_urgc) {
 		sbappendsb(&so->so_rcv, m);
 		m_free(m);
-		sosendoob(so);
+		(void)sosendoob(so);
 		return;
 	}
 
diff --git a/slirp/socket.c b/slirp/socket.c
index a17caa9..84cf13a 100644
--- a/slirp/socket.c
+++ b/slirp/socket.c
@@ -404,7 +404,14 @@ sowrite(struct socket *so)
 	DEBUG_ARG("so = %p", so);
 
 	if (so->so_urgc) {
-		sosendoob(so);
+		if (sosendoob(so) < so->so_urgc) {
+			/* Treat a short write as a fatal error too,
+			 * rather than continuing on and sending the urgent
+			 * data as if it were non-urgent and leaving the
+			 * so_urgc count wrong.
+			 */
+			goto err_disconnected;
+		}
 		if (sb->sb_cc == 0)
 			return 0;
 	}
@@ -448,11 +455,7 @@ sowrite(struct socket *so)
 		return 0;
 
 	if (nn <= 0) {
-		DEBUG_MISC((dfd, " --- sowrite disconnected, so->so_state = %x, errno = %d\n",
-			so->so_state, errno));
-		sofcantsendmore(so);
-		tcp_sockclosed(sototcpcb(so));
-		return -1;
+		goto err_disconnected;
 	}
 
 #ifndef HAVE_READV
@@ -479,6 +482,13 @@ sowrite(struct socket *so)
 		sofcantsendmore(so);
 
 	return nn;
+
+err_disconnected:
+	DEBUG_MISC((dfd, " --- sowrite disconnected, so->so_state = %x, errno = %d\n",
+		    so->so_state, errno));
+	sofcantsendmore(so);
+	tcp_sockclosed(sototcpcb(so));
+	return -1;
 }
 
 /*
-- 
2.7.4

  parent reply	other threads:[~2017-06-05 16:19 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-05 16:19 [Qemu-devel] [PATCH 0/2] slirp: handle errors in sosendoob() Peter Maydell
2017-06-05 16:19 ` [Qemu-devel] [PATCH 1/2] slirp: Handle error returns from slirp_send() " Peter Maydell
2017-07-11 18:05   ` Dr. David Alan Gilbert
2017-07-11 23:24   ` [Qemu-devel] [1/2] " Samuel Thibault
2017-06-05 16:19 ` Peter Maydell [this message]
2017-07-11 18:46   ` [Qemu-devel] [PATCH 2/2] slirp: Handle error returns from sosendoob() Dr. David Alan Gilbert
2017-07-11 20:38     ` Peter Maydell
2017-07-11 23:24   ` [Qemu-devel] [2/2] " Samuel Thibault
2017-06-05 18:22 ` [Qemu-devel] [PATCH 0/2] slirp: handle errors in sosendoob() no-reply
2017-06-26 12:24 ` Peter Maydell
2017-07-09 21:21   ` Peter Maydell
2017-07-09 21:56     ` 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=1496679576-14336-3-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.