Changeset
slirp/ip6.h    |  6 +++---
slirp/misc.c   |  4 +++-
slirp/sbuf.c   |  2 +-
slirp/socket.c | 52 +++++++++++++++++++++++++++++++++++-----------------
4 files changed, 42 insertions(+), 22 deletions(-)
Git apply log
Switched to a new branch '20170715123057.8529-1-samuel.thibault@ens-lyon.org'
Applying: slirp: use DIV_ROUND_UP
Applying: slirp: fork_exec(): Don't close() a negative number in fork_exec()
Applying: slirp: Handle error returns from slirp_send() in sosendoob()
Applying: slirp: Handle error returns from sosendoob()
To https://github.com/patchew-project/qemu
 * [new tag]         patchew/20170715123057.8529-1-samuel.thibault@ens-lyon.org -> patchew/20170715123057.8529-1-samuel.thibault@ens-lyon.org
Test failed: checkpatch

loading

Test passed: FreeBSD

loading

Test passed: s390x

loading

Test passed: docker

loading

[Qemu-devel] [PULL 0/4] slirp updates
Posted by Samuel Thibault, 52 weeks ago
warning: redirection vers https://people.debian.org/~sthibault/qemu.git/
The following changes since commit 4871b51b9241b10f4fd8e04bbb21577886795e25:

  vmgenid-test: use boot-sector infrastructure (2017-07-14 17:03:03 +0100)

are available in the git repository at:

  http://people.debian.org/~sthibault/qemu.git tags/samuel-thibault

for you to fetch changes up to 75cb298d905030fca897ea1d80e409c7f7e3e5ea:

  slirp: Handle error returns from sosendoob() (2017-07-15 14:28:25 +0200)

----------------------------------------------------------------
slirp updates

----------------------------------------------------------------
Marc-André Lureau (1):
      slirp: use DIV_ROUND_UP

Peter Maydell (3):
      slirp: fork_exec(): Don't close() a negative number in fork_exec()
      slirp: Handle error returns from slirp_send() in sosendoob()
      slirp: Handle error returns from sosendoob()

 slirp/ip6.h    |  6 +++---
 slirp/misc.c   |  4 +++-
 slirp/sbuf.c   |  2 +-
 slirp/socket.c | 52 +++++++++++++++++++++++++++++++++++-----------------
 4 files changed, 42 insertions(+), 22 deletions(-)

Re: [Qemu-devel] [PULL 0/4] slirp updates
Posted by no-reply@patchew.org, 52 weeks ago
Hi,

This series seems to have some coding style problems. See output below for
more information:

Subject: [Qemu-devel] [PULL 0/4] slirp updates
Message-id: 20170715123057.8529-1-samuel.thibault@ens-lyon.org
Type: series

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

git config --local diff.renamelimit 0
git config --local diff.renames True

commits="$(git log --format=%H --reverse $BASE..)"
for c in $commits; do
    echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
    if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
        failed=1
        echo
    fi
    n=$((n+1))
done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 * [new tag]         patchew/20170715123057.8529-1-samuel.thibault@ens-lyon.org -> patchew/20170715123057.8529-1-samuel.thibault@ens-lyon.org
Switched to a new branch 'test'
d550cce slirp: Handle error returns from sosendoob()
3ccee6a slirp: Handle error returns from slirp_send() in sosendoob()
17f0f61 slirp: fork_exec(): Don't close() a negative number in fork_exec()
861877a6 slirp: use DIV_ROUND_UP

=== OUTPUT BEGIN ===
Checking PATCH 1/4: slirp: use DIV_ROUND_UP...
Checking PATCH 2/4: slirp: fork_exec(): Don't close() a negative number in fork_exec()...
ERROR: code indent should never use tabs
#27: FILE: slirp/misc.c:115:
+^I^I^Iif (s >= 0) {$

ERROR: code indent should never use tabs
#28: FILE: slirp/misc.c:116:
+^I^I^I    closesocket(s);$

ERROR: code indent should never use tabs
#29: FILE: slirp/misc.c:117:
+^I^I^I}$

total: 3 errors, 0 warnings, 10 lines checked

Your patch has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

Checking PATCH 3/4: slirp: Handle error returns from slirp_send() in sosendoob()...
ERROR: code indent should never use tabs
#35: FILE: slirp/socket.c:354:
+^I^Iuint32_t urgc = so->so_urgc;$

ERROR: code indent should never use tabs
#38: FILE: slirp/socket.c:356:
+^I^Iif (len > urgc) {$

ERROR: code indent should never use tabs
#39: FILE: slirp/socket.c:357:
+^I^I^Ilen = urgc;$

ERROR: code indent should never use tabs
#40: FILE: slirp/socket.c:358:
+^I^I}$

ERROR: code indent should never use tabs
#44: FILE: slirp/socket.c:360:
+^I^Iurgc -= len;$

ERROR: code indent should never use tabs
#45: FILE: slirp/socket.c:361:
+^I^Iif (urgc) {$

ERROR: code indent should never use tabs
#48: FILE: slirp/socket.c:363:
+^I^I^Iif (n > urgc) {$

ERROR: code indent should never use tabs
#49: FILE: slirp/socket.c:364:
+^I^I^I^In = urgc;$

ERROR: code indent should never use tabs
#50: FILE: slirp/socket.c:365:
+^I^I^I}$

ERROR: code indent should never use tabs
#56: FILE: slirp/socket.c:370:
+^I}$

ERROR: code indent should never use tabs
#61: FILE: slirp/socket.c:373:
+^Iif (n != len) {$

ERROR: code indent should never use tabs
#62: FILE: slirp/socket.c:374:
+^I^IDEBUG_ERROR((dfd, "Didn't send all data urgently XXXXX\n"));$

ERROR: code indent should never use tabs
#63: FILE: slirp/socket.c:375:
+^I}$

ERROR: code indent should never use tabs
#66: FILE: slirp/socket.c:377:
+^Iif (n < 0) {$

ERROR: code indent should never use tabs
#67: FILE: slirp/socket.c:378:
+^I^Ireturn n;$

ERROR: code indent should never use tabs
#69: FILE: slirp/socket.c:380:
+^Iso->so_urgc -= n;$

ERROR: line over 90 characters
#70: FILE: slirp/socket.c:381:
+	DEBUG_MISC((dfd, " ---2 sent %d bytes urgent data, %d urgent bytes left\n", n, so->so_urgc));

ERROR: code indent should never use tabs
#70: FILE: slirp/socket.c:381:
+^IDEBUG_MISC((dfd, " ---2 sent %d bytes urgent data, %d urgent bytes left\n", n, so->so_urgc));$

total: 18 errors, 0 warnings, 51 lines checked

Your patch has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

Checking PATCH 4/4: slirp: Handle error returns from sosendoob()...
ERROR: code indent should never use tabs
#27: FILE: slirp/sbuf.c:94:
+^I^I(void)sosendoob(so);$

ERROR: code indent should never use tabs
#40: FILE: slirp/socket.c:407:
+^I^Iuint32_t expected = so->so_urgc;$

ERROR: code indent should never use tabs
#41: FILE: slirp/socket.c:408:
+^I^Iif (sosendoob(so) < expected) {$

ERROR: code indent should never use tabs
#42: FILE: slirp/socket.c:409:
+^I^I^I/* Treat a short write as a fatal error too,$

ERROR: code indent should never use tabs
#43: FILE: slirp/socket.c:410:
+^I^I^I * rather than continuing on and sending the urgent$

ERROR: code indent should never use tabs
#44: FILE: slirp/socket.c:411:
+^I^I^I * data as if it were non-urgent and leaving the$

ERROR: code indent should never use tabs
#45: FILE: slirp/socket.c:412:
+^I^I^I * so_urgc count wrong.$

ERROR: code indent should never use tabs
#46: FILE: slirp/socket.c:413:
+^I^I^I */$

ERROR: code indent should never use tabs
#47: FILE: slirp/socket.c:414:
+^I^I^Igoto err_disconnected;$

ERROR: code indent should never use tabs
#48: FILE: slirp/socket.c:415:
+^I^I}$

ERROR: code indent should never use tabs
#61: FILE: slirp/socket.c:459:
+^I^Igoto err_disconnected;$

WARNING: line over 80 characters
#71: FILE: slirp/socket.c:488:
+	DEBUG_MISC((dfd, " --- sowrite disconnected, so->so_state = %x, errno = %d\n",

ERROR: code indent should never use tabs
#71: FILE: slirp/socket.c:488:
+^IDEBUG_MISC((dfd, " --- sowrite disconnected, so->so_state = %x, errno = %d\n",$

ERROR: code indent should never use tabs
#72: FILE: slirp/socket.c:489:
+^I^I    so->so_state, errno));$

ERROR: code indent should never use tabs
#73: FILE: slirp/socket.c:490:
+^Isofcantsendmore(so);$

ERROR: code indent should never use tabs
#74: FILE: slirp/socket.c:491:
+^Itcp_sockclosed(sototcpcb(so));$

ERROR: code indent should never use tabs
#75: FILE: slirp/socket.c:492:
+^Ireturn -1;$

total: 16 errors, 1 warnings, 49 lines checked

Your patch has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

=== OUTPUT END ===

Test command exited with code: 1


---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-devel@freelists.org
Re: [Qemu-devel] [PULL 0/4] slirp updates
Posted by Peter Maydell, 52 weeks ago
On 15 July 2017 at 13:30, Samuel Thibault <samuel.thibault@ens-lyon.org> wrote:
> warning: redirection vers https://people.debian.org/~sthibault/qemu.git/
> The following changes since commit 4871b51b9241b10f4fd8e04bbb21577886795e25:
>
>   vmgenid-test: use boot-sector infrastructure (2017-07-14 17:03:03 +0100)
>
> are available in the git repository at:
>
>   http://people.debian.org/~sthibault/qemu.git tags/samuel-thibault
>
> for you to fetch changes up to 75cb298d905030fca897ea1d80e409c7f7e3e5ea:
>
>   slirp: Handle error returns from sosendoob() (2017-07-15 14:28:25 +0200)
>
> ----------------------------------------------------------------
> slirp updates
>
> ----------------------------------------------------------------
> Marc-André Lureau (1):
>       slirp: use DIV_ROUND_UP
>
> Peter Maydell (3):
>       slirp: fork_exec(): Don't close() a negative number in fork_exec()
>       slirp: Handle error returns from slirp_send() in sosendoob()
>       slirp: Handle error returns from sosendoob()
>
>  slirp/ip6.h    |  6 +++---
>  slirp/misc.c   |  4 +++-
>  slirp/sbuf.c   |  2 +-
>  slirp/socket.c | 52 +++++++++++++++++++++++++++++++++++-----------------
>  4 files changed, 42 insertions(+), 22 deletions(-)

Applied, thanks.

-- PMM

[Qemu-devel] [PULL 1/4] slirp: use DIV_ROUND_UP
Posted by Samuel Thibault, 52 weeks ago
From: Marc-André Lureau <marcandre.lureau@redhat.com>

I used the clang-tidy qemu-round check to generate the fix:
https://github.com/elmarco/clang-tools-extra

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
---
 slirp/ip6.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/slirp/ip6.h b/slirp/ip6.h
index 0908855f0f..b1bea43b3c 100644
--- a/slirp/ip6.h
+++ b/slirp/ip6.h
@@ -57,9 +57,9 @@ static inline bool in6_equal_mach(const struct in6_addr *a,
                                   const struct in6_addr *b,
                                   int prefix_len)
 {
-    if (memcmp(&(a->s6_addr[(prefix_len + 7) / 8]),
-               &(b->s6_addr[(prefix_len + 7) / 8]),
-               16 - (prefix_len + 7) / 8) != 0) {
+    if (memcmp(&(a->s6_addr[DIV_ROUND_UP(prefix_len, 8)]),
+               &(b->s6_addr[DIV_ROUND_UP(prefix_len, 8)]),
+               16 - DIV_ROUND_UP(prefix_len, 8)) != 0) {
         return 0;
     }
 
-- 
2.13.2


[Qemu-devel] [PULL 2/4] slirp: fork_exec(): Don't close() a negative number in fork_exec()
Posted by Samuel Thibault, 52 weeks ago
From: Peter Maydell <peter.maydell@linaro.org>

In a fork_exec() error path we try to closesocket(s) when s might
be a negative number because the thing that failed was the
qemu_socket() call. Add a guard so we don't do this.

(Spotted by Coverity: CID 1005727 issue 1 of 2.)

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>
---
 slirp/misc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/slirp/misc.c b/slirp/misc.c
index 88e9d94197..260187b6b6 100644
--- a/slirp/misc.c
+++ b/slirp/misc.c
@@ -112,7 +112,9 @@ fork_exec(struct socket *so, const char *ex, int do_pty)
 		    bind(s, (struct sockaddr *)&addr, addrlen) < 0 ||
 		    listen(s, 1) < 0) {
 			error_report("Error: inet socket: %s", strerror(errno));
-			closesocket(s);
+			if (s >= 0) {
+			    closesocket(s);
+			}
 
 			return 0;
 		}
-- 
2.13.2


[Qemu-devel] [PULL 3/4] slirp: Handle error returns from slirp_send() in sosendoob()
Posted by Samuel Thibault, 52 weeks ago
From: Peter Maydell <peter.maydell@linaro.org>

The code in sosendoob() assumes that slirp_send() always
succeeds, but it might return an OS error code (for instance
if the other end has disconnected). Catch these and return
the caller either -1 on error or the number of urgent bytes
actually written. (None of the callers check this return
value currently, though.)

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>
---
 slirp/socket.c | 29 ++++++++++++++++++-----------
 1 file changed, 18 insertions(+), 11 deletions(-)

diff --git a/slirp/socket.c b/slirp/socket.c
index 3b49a69a93..a17caa9fa7 100644
--- a/slirp/socket.c
+++ b/slirp/socket.c
@@ -345,33 +345,40 @@ sosendoob(struct socket *so)
 	if (sb->sb_rptr < sb->sb_wptr) {
 		/* We can send it directly */
 		n = slirp_send(so, sb->sb_rptr, so->so_urgc, (MSG_OOB)); /* |MSG_DONTWAIT)); */
-		so->so_urgc -= n;
-
-		DEBUG_MISC((dfd, " --- sent %d bytes urgent data, %d urgent bytes left\n", n, so->so_urgc));
 	} else {
 		/*
 		 * Since there's no sendv or sendtov like writev,
 		 * we must copy all data to a linear buffer then
 		 * send it all
 		 */
+		uint32_t urgc = so->so_urgc;
 		len = (sb->sb_data + sb->sb_datalen) - sb->sb_rptr;
-		if (len > so->so_urgc) len = so->so_urgc;
+		if (len > urgc) {
+			len = urgc;
+		}
 		memcpy(buff, sb->sb_rptr, len);
-		so->so_urgc -= len;
-		if (so->so_urgc) {
+		urgc -= len;
+		if (urgc) {
 			n = sb->sb_wptr - sb->sb_data;
-			if (n > so->so_urgc) n = so->so_urgc;
+			if (n > urgc) {
+				n = urgc;
+			}
 			memcpy((buff + len), sb->sb_data, n);
-			so->so_urgc -= n;
 			len += n;
 		}
 		n = slirp_send(so, buff, len, (MSG_OOB)); /* |MSG_DONTWAIT)); */
+	}
+
 #ifdef DEBUG
-		if (n != len)
-		   DEBUG_ERROR((dfd, "Didn't send all data urgently XXXXX\n"));
+	if (n != len) {
+		DEBUG_ERROR((dfd, "Didn't send all data urgently XXXXX\n"));
+	}
 #endif
-		DEBUG_MISC((dfd, " ---2 sent %d bytes urgent data, %d urgent bytes left\n", n, so->so_urgc));
+	if (n < 0) {
+		return n;
 	}
+	so->so_urgc -= n;
+	DEBUG_MISC((dfd, " ---2 sent %d bytes urgent data, %d urgent bytes left\n", n, so->so_urgc));
 
 	sb->sb_cc -= n;
 	sb->sb_rptr += n;
-- 
2.13.2


[Qemu-devel] [PULL 4/4] slirp: Handle error returns from sosendoob()
Posted by Samuel Thibault, 52 weeks ago
From: Peter Maydell <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>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
---
 slirp/sbuf.c   |  2 +-
 slirp/socket.c | 23 +++++++++++++++++------
 2 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/slirp/sbuf.c b/slirp/sbuf.c
index 10119d3ad5..912f235f65 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 a17caa9fa7..ecec0295a9 100644
--- a/slirp/socket.c
+++ b/slirp/socket.c
@@ -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;
 	}
@@ -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
@@ -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;
 }
 
 /*
-- 
2.13.2