Skip to content

Commit

Permalink
slirp: Handle error returns from sosendoob()
Browse files Browse the repository at this point in the history
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>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
  • Loading branch information
pm215 authored and sthibaul committed Jul 15, 2017
1 parent 0b46606 commit 75cb298
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion slirp/sbuf.c
Expand Up @@ -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;
}

Expand Down
23 changes: 17 additions & 6 deletions slirp/socket.c
Expand Up @@ -404,7 +404,15 @@ sowrite(struct socket *so)
DEBUG_ARG("so = %p", so);

if (so->so_urgc) {
sosendoob(so);
uint32_t expected = so->so_urgc;
if (sosendoob(so) < expected) {
/* 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;
}
Expand Down Expand Up @@ -448,11 +456,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
Expand All @@ -479,6 +483,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;
}

/*
Expand Down

0 comments on commit 75cb298

Please sign in to comment.