[Qemu-devel] [PATCH v3] slirp: check for ioctlsocket error and 0-length udp payload.

Vic Lee posted 1 patch 6 years, 7 months ago
Test asan failed
Test docker-mingw@fedora failed
Test docker-clang@ubuntu failed
Test checkpatch passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20190301084814.11076-1-llyzs.vic@gmail.com
Maintainers: Jan Kiszka <jan.kiszka@siemens.com>, Samuel Thibault <samuel.thibault@ens-lyon.org>
slirp/socket.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
[Qemu-devel] [PATCH v3] slirp: check for ioctlsocket error and 0-length udp payload.
Posted by Vic Lee 6 years, 7 months ago
Sometimes sorecvfrom() is called from slirp.c because revents == G_IO_IN,
but there is 0 bytes available and recvfrom could be blocking indefinitely.
This is likely due to 0-length udp payload. This also adds an error
checking for ioctlsocket.

Signed-off-by: Vic Lee <llyzs.vic@gmail.com>
---
 slirp/socket.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/slirp/socket.c b/slirp/socket.c
index 4876ea3f31..af732f78fb 100644
--- a/slirp/socket.c
+++ b/slirp/socket.c
@@ -529,6 +529,15 @@ sorecvfrom(struct socket *so)
           int n;
 #endif
 
+            if (ioctlsocket(so->s, FIONREAD, &n) != 0) {
+                DEBUG_MISC((dfd, " ioctlsocket errno = %d-%s\n",
+                            errno, strerror(errno)));
+                return;
+            }
+            if (n == 0) {
+                return;
+            }
+
 	  m = m_get(so->slirp);
 	  if (!m) {
 	      return;
@@ -552,7 +561,6 @@ sorecvfrom(struct socket *so)
 	   */
 	  len = M_FREEROOM(m);
 	  /* if (so->so_fport != htons(53)) { */
-	  ioctlsocket(so->s, FIONREAD, &n);
 
 	  if (n > len) {
 	    n = (m->m_data - m->m_dat) + m->m_len + n + 1;
-- 
2.20.1


Re: [Qemu-devel] [PATCH v3] slirp: check for ioctlsocket error and 0-length udp payload.
Posted by no-reply@patchew.org 6 years, 7 months ago
Patchew URL: https://patchew.org/QEMU/20190301084814.11076-1-llyzs.vic@gmail.com/



Hi,

This series failed the docker-mingw@fedora build test. Please find the testing commands and
their output below. If you have Docker installed, you can probably reproduce it
locally.

=== TEST SCRIPT BEGIN ===
#!/bin/bash
time make docker-test-mingw@fedora SHOW_ENV=1 J=14 NETWORK=1
=== TEST SCRIPT END ===

                 from /tmp/qemu-test/src/slirp/slirp.h:50,
                 from /tmp/qemu-test/src/slirp/socket.c:8:
/tmp/qemu-test/src/slirp/socket.c: In function 'sorecvfrom':
/tmp/qemu-test/src/slirp/socket.c:533:29: error: 'dfd' undeclared (first use in this function)
                 DEBUG_MISC((dfd, " ioctlsocket errno = %d-%s\n",
                             ^~~
/usr/x86_64-w64-mingw32/sys-root/mingw/include/glib-2.0/glib/gmessages.h:345:32: note: in definition of macro 'g_debug'
---
/tmp/qemu-test/src/slirp/socket.c:533:17: note: in expansion of macro 'DEBUG_MISC'
                 DEBUG_MISC((dfd, " ioctlsocket errno = %d-%s\n",
                 ^~~~~~~~~~
/tmp/qemu-test/src/slirp/socket.c:533:32: error: left-hand operand of comma expression has no effect [-Werror=unused-value]
                 DEBUG_MISC((dfd, " ioctlsocket errno = %d-%s\n",
                                ^
/usr/x86_64-w64-mingw32/sys-root/mingw/include/glib-2.0/glib/gmessages.h:345:32: note: in definition of macro 'g_debug'
---
/tmp/qemu-test/src/slirp/socket.c:533:17: note: in expansion of macro 'DEBUG_MISC'
                 DEBUG_MISC((dfd, " ioctlsocket errno = %d-%s\n",
                 ^~~~~~~~~~
/tmp/qemu-test/src/slirp/socket.c:533:64: error: left-hand operand of comma expression has no effect [-Werror=unused-value]
                 DEBUG_MISC((dfd, " ioctlsocket errno = %d-%s\n",
                                                                ^
/usr/x86_64-w64-mingw32/sys-root/mingw/include/glib-2.0/glib/gmessages.h:345:32: note: in definition of macro 'g_debug'
---
/tmp/qemu-test/src/slirp/socket.c:533:17: note: in expansion of macro 'DEBUG_MISC'
                 DEBUG_MISC((dfd, " ioctlsocket errno = %d-%s\n",
                 ^~~~~~~~~~
/tmp/qemu-test/src/slirp/socket.c:533:17: error: format not a string literal and no format arguments [-Werror=format-security]
cc1: all warnings being treated as errors
make: *** [/tmp/qemu-test/src/rules.mak:69: slirp/socket.o] Error 1
Traceback (most recent call last):


The full log is available at
http://patchew.org/logs/20190301084814.11076-1-llyzs.vic@gmail.com/testing.docker-mingw@fedora/?type=message.
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-devel@redhat.com