[Spice-devel] [spice-server PATCH 4/8] main-channel: getpeername/getsockname return early if no sockfd

Uri Lublin uril at redhat.com
Sun Oct 16 11:44:51 UTC 2016


I'm not sure that needed as it seems getpeername/getsockname
accept int fd and return -1 for fd=-1

Signed-off-by: Uri Lublin <uril at redhat.com>
---
 server/main-channel.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/server/main-channel.c b/server/main-channel.c
index bf84694..9ff4dcd 100644
--- a/server/main-channel.c
+++ b/server/main-channel.c
@@ -281,12 +281,24 @@ MainChannelClient *main_channel_link(MainChannel *channel, RedClient *client,
 
 int main_channel_getsockname(MainChannel *main_chan, struct sockaddr *sa, socklen_t *salen)
 {
-    return main_chan ? getsockname(red_channel_get_first_socket(&main_chan->base), sa, salen) : -1;
+    int socketfd;
+
+    if (!main_chan || ((socketfd = red_channel_get_first_socket(&main_chan->base)) < 0)) {
+        return -1;
+    }
+
+    return getsockname(socketfd, sa, salen);
 }
 
 int main_channel_getpeername(MainChannel *main_chan, struct sockaddr *sa, socklen_t *salen)
 {
-    return main_chan ? getpeername(red_channel_get_first_socket(&main_chan->base), sa, salen) : -1;
+    int socketfd;
+
+    if (!main_chan || ((socketfd = red_channel_get_first_socket(&main_chan->base)) < 0)) {
+        return -1;
+    }
+
+    return getpeername(socketfd, sa, salen);
 }
 
 // TODO: ? shouldn't it disonnect all clients? or shutdown all main_channels?
-- 
2.7.4



More information about the Spice-devel mailing list