[vlc-commits] netsync: check received packet sizes

Rémi Denis-Courmont git at videolan.org
Mon Aug 18 19:43:23 CEST 2014


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Aug 18 20:43:13 2014 +0300| [d760499fd9bfdcac0706476d742bd539e3c944cb] | committer: Rémi Denis-Courmont

netsync: check received packet sizes

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=d760499fd9bfdcac0706476d742bd539e3c944cb
---

 modules/control/netsync.c |   21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/modules/control/netsync.c b/modules/control/netsync.c
index b833141..05b18b2 100644
--- a/modules/control/netsync.c
+++ b/modules/control/netsync.c
@@ -187,9 +187,11 @@ static void *Master(void *handle)
 
         /* We received something */
         struct sockaddr_storage from;
-        unsigned struct_size = sizeof(from);
-        recvfrom(sys->fd, data, sizeof(data), 0,
-                 (struct sockaddr*)&from, &struct_size);
+        socklen_t fromlen = sizeof (from);
+
+        if (recvfrom(sys->fd, data, 8, 0,
+                     (struct sockaddr *)&from, &fromlen) < 8)
+            continue;
 
         mtime_t master_system = GetPcrSystem(sys->input);
         if (master_system < 0)
@@ -199,8 +201,8 @@ static void *Master(void *handle)
         data[1] = hton64(master_system);
 
         /* Reply to the sender */
-        sendto(sys->fd, data, sizeof(data), 0,
-               (struct sockaddr *)&from, struct_size);
+        sendto(sys->fd, data, 16, 0,
+               (struct sockaddr *)&from, fromlen);
 #if 0
         /* not sure we need the client information to sync,
            since we are the master anyway */
@@ -228,18 +230,17 @@ static void *Slave(void *handle)
             goto wait;
 
         /* Send clock request to the master */
-        data[0] = hton64(system);
-
         const mtime_t send_date = mdate();
-        if (send(sys->fd, data, sizeof(data[0]), 0) <= 0)
-            goto wait;
+
+        data[0] = hton64(system);
+        send(sys->fd, data, 8, 0);
 
         /* Don't block */
         if (poll(&ufd, 1, sys->timeout) <= 0)
             continue;
 
         const mtime_t receive_date = mdate();
-        if (recv(sys->fd, data, sizeof(data), 0) <= 0)
+        if (recv(sys->fd, data, 16, 0) < 16)
             goto wait;
 
         const mtime_t master_date   = ntoh64(data[0]);



More information about the vlc-commits mailing list