qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v4 1/4] net/socket: Drop the odd 'default' case


From: Mao Zhongyi
Subject: Re: [Qemu-devel] [PATCH v4 1/4] net/socket: Drop the odd 'default' case and comment
Date: Mon, 26 Jun 2017 14:13:19 +0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0

Hi, Markus


On 06/23/2017 09:36 PM, Markus Armbruster wrote:
Mao Zhongyi <address@hidden> writes:

In the net_socket_fd_init(), the 'default' case and comment is odd.
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.

If there is a genuine reason to support something like SOCK_RAW, it
should be explicitly handled.

So, drop the 'default' case since it is broken already.

Cc: address@hidden
Cc: address@hidden
Cc: address@hidden
Cc: address@hidden
Suggested-by: Markus Armbruster <address@hidden>
Suggested-by: Daniel P. Berrange <address@hidden>
Signed-off-by: Mao Zhongyi <address@hidden>
---
 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;
 }

You don't actually "drop the 'default' case", as your commit message
claims.  Perhaps:

    net/socket: Don't treat odd socket type as SOCK_STREAM

    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 handled explicitly.

With something like that:


Yes, I have noticed that the commit message is really not very match this
patch after read your exact description. I will fix it in the next version.

Thank you very much. :)
Mao

Reviewed-by: Markus Armbruster <address@hidden>








reply via email to

[Prev in Thread] Current Thread [Next in Thread]