summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--toxcore/Lossless_UDP.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/toxcore/Lossless_UDP.c b/toxcore/Lossless_UDP.c
index 0d6d8694..3858716d 100644
--- a/toxcore/Lossless_UDP.c
+++ b/toxcore/Lossless_UDP.c
@@ -297,6 +297,10 @@ uint32_t sendqueue(Lossless_UDP *ludp, int connection_id)
297 return 0; 297 return 0;
298 298
299 Connection *connection = &tox_array_get(&ludp->connections, connection_id, Connection); 299 Connection *connection = &tox_array_get(&ludp->connections, connection_id, Connection);
300
301 if (connection->status == 0)
302 return 0;
303
300 return connection->sendbuff_packetnum - connection->successful_sent; 304 return connection->sendbuff_packetnum - connection->successful_sent;
301} 305}
302 306
@@ -307,6 +311,10 @@ uint32_t recvqueue(Lossless_UDP *ludp, int connection_id)
307 return 0; 311 return 0;
308 312
309 Connection *connection = &tox_array_get(&ludp->connections, connection_id, Connection); 313 Connection *connection = &tox_array_get(&ludp->connections, connection_id, Connection);
314
315 if (connection->status == 0)
316 return 0;
317
310 return connection->recv_packetnum - connection->successful_read; 318 return connection->recv_packetnum - connection->successful_read;
311} 319}
312 320
@@ -335,6 +343,10 @@ int read_packet(Lossless_UDP *ludp, int connection_id, uint8_t *data)
335 return 0; 343 return 0;
336 344
337 Connection *connection = &tox_array_get(&ludp->connections, connection_id, Connection); 345 Connection *connection = &tox_array_get(&ludp->connections, connection_id, Connection);
346
347 if (connection->status == 0)
348 return 0;
349
338 uint16_t index = connection->successful_read % MAX_QUEUE_NUM; 350 uint16_t index = connection->successful_read % MAX_QUEUE_NUM;
339 uint16_t size = connection->recvbuffer[index].size; 351 uint16_t size = connection->recvbuffer[index].size;
340 memcpy(data, connection->recvbuffer[index].data, size); 352 memcpy(data, connection->recvbuffer[index].data, size);
@@ -349,10 +361,17 @@ int read_packet(Lossless_UDP *ludp, int connection_id, uint8_t *data)
349 */ 361 */
350int write_packet(Lossless_UDP *ludp, int connection_id, uint8_t *data, uint32_t length) 362int write_packet(Lossless_UDP *ludp, int connection_id, uint8_t *data, uint32_t length)
351{ 363{
364 if ((unsigned int)connection_id >= ludp->connections.len)
365 return 0;
366
352 if (length > MAX_DATA_SIZE || length == 0 || sendqueue(ludp, connection_id) >= BUFFER_PACKET_NUM) 367 if (length > MAX_DATA_SIZE || length == 0 || sendqueue(ludp, connection_id) >= BUFFER_PACKET_NUM)
353 return 0; 368 return 0;
354 369
355 Connection *connection = &tox_array_get(&ludp->connections, connection_id, Connection); 370 Connection *connection = &tox_array_get(&ludp->connections, connection_id, Connection);
371
372 if (connection->status == 0)
373 return 0;
374
356 uint32_t index = connection->sendbuff_packetnum % MAX_QUEUE_NUM; 375 uint32_t index = connection->sendbuff_packetnum % MAX_QUEUE_NUM;
357 memcpy(connection->sendbuffer[index].data, data, length); 376 memcpy(connection->sendbuffer[index].data, data, length);
358 connection->sendbuffer[index].size = length; 377 connection->sendbuffer[index].size = length;