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)
/* 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]);
......
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