Repository : ssh://git@open-mesh.org/alfred
On branch : master
commit b5f8774fd64cb127a0fd152e75c138cbef366788 Author: Sven Eckelmann sven@narfation.org Date: Sun May 31 13:35:56 2015 +0200
alfred: Make buffer size check before sending explicit
The sending code is automatically transmitting a packet when the next data block would not fit inside the outgoing, aggregated UDP packet. But the code does not check whether the data would then fit inside the new, complete empty push_data packet. It is currently no problem because alfred has the restriction that a dataset never stores a buffer larger than (MAX_PAYLOAD - sizeof(struct alfred_push_data_v0) - sizeof(struct alfred_data)). Therefore, the length check for the empty push_data packet + dataset buffer would never fail.
Nonetheless, make this check explicit to avoid problems when the receiving code is changed or the sending code gets the ability to limit the size of outgoing UDP packets.
Reported-by: Hans-Werner Hilse hwhilse@gmail.com Signed-off-by: Sven Eckelmann sven@narfation.org [sw: use reworded commit message] Signed-off-by: Simon Wunderlich sw@simonwunderlich.de
b5f8774fd64cb127a0fd152e75c138cbef366788 send.c | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/send.c b/send.c index 8853970..5a92132 100644 --- a/send.c +++ b/send.c @@ -91,6 +91,11 @@ int push_data(struct globals *globals, struct interface *interface, total_length = 0; }
+ /* still too large? - should never happen */ + if (total_length + dataset->data.header.length + sizeof(*data) > + MAX_PAYLOAD - sizeof(*push)) + continue; + data = (struct alfred_data *) (buf + sizeof(*push) + total_length); memcpy(data, &dataset->data, sizeof(*data));