Properly catch errors in recvfrom
authorJens Georg <mail@jensge.org>
Tue, 7 Sep 2010 20:20:42 +0000 (22:20 +0200)
committerZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Tue, 14 Sep 2010 13:35:59 +0000 (16:35 +0300)
Errors previously were caught by sheer luck due to the fact that bytes
was declared size_t (unsigned), thus -1 mapping to typeof(size_t)_MAX
which most likely fullfilled the case of bytes > BUF_SIZE

libgssdp/gssdp-client.c

index 0792f94..3cef6e4 100644 (file)
@@ -713,7 +713,7 @@ static gboolean
 socket_source_cb (GSSDPSocketSource *socket, GSSDPClient *client)
 {
         int fd, type, len;
-        size_t bytes;
+        ssize_t bytes;
         char buf[BUF_SIZE], *end;
         struct sockaddr_in addr;
         socklen_t addr_size;
@@ -734,6 +734,13 @@ socket_source_cb (GSSDPSocketSource *socket, GSSDPClient *client)
                           MSG_TRUNC,
                           (struct sockaddr *) &addr,
                           &addr_size);
+        if (bytes == -1) {
+                g_warning ("Failed to read from socket: %d (%s)",
+                           errno,
+                           strerror (errno));
+
+                return TRUE;
+        }
 
         /* We need the following lines to make sure the right client received
          * the packet. We won't need to do this if there was any way to tell