From d760499fd9bfdcac0706476d742bd539e3c944cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Denis-Courmont?= Date: Mon, 18 Aug 2014 20:43:13 +0300 Subject: [PATCH] netsync: check received packet sizes --- 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 b833141b1f..05b18b291f 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]); -- GitLab