Commit d760499f authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

netsync: check received packet sizes

parent 228182fe
...@@ -187,9 +187,11 @@ static void *Master(void *handle) ...@@ -187,9 +187,11 @@ static void *Master(void *handle)
/* We received something */ /* We received something */
struct sockaddr_storage from; struct sockaddr_storage from;
unsigned struct_size = sizeof(from); socklen_t fromlen = sizeof (from);
recvfrom(sys->fd, data, sizeof(data), 0,
(struct sockaddr*)&from, &struct_size); if (recvfrom(sys->fd, data, 8, 0,
(struct sockaddr *)&from, &fromlen) < 8)
continue;
mtime_t master_system = GetPcrSystem(sys->input); mtime_t master_system = GetPcrSystem(sys->input);
if (master_system < 0) if (master_system < 0)
...@@ -199,8 +201,8 @@ static void *Master(void *handle) ...@@ -199,8 +201,8 @@ static void *Master(void *handle)
data[1] = hton64(master_system); data[1] = hton64(master_system);
/* Reply to the sender */ /* Reply to the sender */
sendto(sys->fd, data, sizeof(data), 0, sendto(sys->fd, data, 16, 0,
(struct sockaddr *)&from, struct_size); (struct sockaddr *)&from, fromlen);
#if 0 #if 0
/* not sure we need the client information to sync, /* not sure we need the client information to sync,
since we are the master anyway */ since we are the master anyway */
...@@ -228,18 +230,17 @@ static void *Slave(void *handle) ...@@ -228,18 +230,17 @@ static void *Slave(void *handle)
goto wait; goto wait;
/* Send clock request to the master */ /* Send clock request to the master */
data[0] = hton64(system);
const mtime_t send_date = mdate(); 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 */ /* Don't block */
if (poll(&ufd, 1, sys->timeout) <= 0) if (poll(&ufd, 1, sys->timeout) <= 0)
continue; continue;
const mtime_t receive_date = mdate(); 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; goto wait;
const mtime_t master_date = ntoh64(data[0]); const mtime_t master_date = ntoh64(data[0]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment