All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
To: qemu-devel@nongnu.org
Cc: jasowang@redhat.com, armbru@redhat.com, berrange@redhat.com
Subject: [Qemu-devel] [PATCH v6 1/4] net/socket: Don't treat odd socket type as SOCK_STREAM
Date: Wed, 28 Jun 2017 21:08:47 +0800	[thread overview]
Message-ID: <d9660b46628b52aa8c63c21fe20618b5bc33bb4c.1498654240.git.maozy.fnst@cn.fujitsu.com> (raw)
In-Reply-To: <cover.1498654240.git.maozy.fnst@cn.fujitsu.com>

In net_socket_fd_init(), the 'default' case is odd: it warns,
then continues as if the socket type was SOCK_STREAM. The
comment explains "this could be a eg. a pty", but that makes
no sense. If @fd really was a pty, getsockopt() would fail
with ENOTSOCK. If @fd was a socket, but neither SOCK_DGRAM nor
SOCK_STREAM. It should not be treated as if it was SOCK_STREAM.

Turn this case into an Error. If there is a genuine reason to
support something like SOCK_RAW, it should be explicitly
handled.

Cc: jasowang@redhat.com
Cc: armbru@redhat.com
Cc: berrange@redhat.com
Cc: armbru@redhat.com
Suggested-by: Markus Armbruster <armbru@redhat.com>
Suggested-by: Daniel P. Berrange <berrange@redhat.com>
Signed-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
---
 net/socket.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/net/socket.c b/net/socket.c
index dcae1ae..53765bd 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -449,9 +449,9 @@ static NetSocketState *net_socket_fd_init(NetClientState *peer,
     case SOCK_STREAM:
         return net_socket_fd_init_stream(peer, model, name, fd, is_connected);
     default:
-        /* who knows ... this could be a eg. a pty, do warn and continue as stream */
-        fprintf(stderr, "qemu: warning: socket type=%d for fd=%d is not SOCK_DGRAM or SOCK_STREAM\n", so_type, fd);
-        return net_socket_fd_init_stream(peer, model, name, fd, is_connected);
+        error_report("qemu: error: socket type=%d for fd=%d is not"
+                " SOCK_DGRAM or SOCK_STREAM", so_type, fd);
+        closesocket(fd);
     }
     return NULL;
 }
-- 
2.9.4

  reply	other threads:[~2017-06-28 13:09 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-28 13:08 [Qemu-devel] [PATCH v6 0/4] Improve error reporting Mao Zhongyi
2017-06-28 13:08 ` Mao Zhongyi [this message]
2017-06-28 13:18   ` [Qemu-devel] [PATCH v6 1/4] net/socket: Don't treat odd socket type as SOCK_STREAM Daniel P. Berrange
2017-06-28 14:23     ` Eric Blake
2017-06-29  3:24       ` Mao Zhongyi
2017-06-28 13:08 ` [Qemu-devel] [PATCH v6 2/4] net/socket: Convert several helper functions to Error Mao Zhongyi
2017-06-28 13:21   ` Daniel P. Berrange
2017-06-28 13:08 ` [Qemu-devel] [PATCH v6 3/4] net/net: Convert parse_host_port() " Mao Zhongyi
2017-06-28 13:23   ` Daniel P. Berrange
2017-06-28 14:24     ` Eric Blake
2017-06-28 14:28       ` Daniel P. Berrange
2017-06-29  7:29         ` Markus Armbruster
2017-06-29  3:01     ` Mao Zhongyi
2017-06-28 13:08 ` [Qemu-devel] [PATCH v6 4/4] net/socket: Improve -net socket error reporting Mao Zhongyi
2017-06-28 13:27   ` Daniel P. Berrange
2017-06-29  3:08     ` Mao Zhongyi
2017-06-29  7:31       ` Markus Armbruster

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=d9660b46628b52aa8c63c21fe20618b5bc33bb4c.1498654240.git.maozy.fnst@cn.fujitsu.com \
    --to=maozy.fnst@cn.fujitsu.com \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=qemu-devel@nongnu.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.