summaryrefslogtreecommitdiff
path: root/toxcore/Messenger.c
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2015-10-21 21:01:13 -0400
committerirungentoo <irungentoo@gmail.com>2015-10-21 21:01:13 -0400
commita25cc96b4f2aeaca169df834e39df796ac08f1bd (patch)
treeddee7b9fa08a8485c1f625951492b27e28527507 /toxcore/Messenger.c
parent085c942b34c8bd410ecd22579a280a1df12c21c0 (diff)
Prevent seek equal to size of file transfer so that toxcore respects what the docs say.
Diffstat (limited to 'toxcore/Messenger.c')
-rw-r--r--toxcore/Messenger.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index 2ff2ac13..887c3702 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -1264,7 +1264,7 @@ int file_seek(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uin
1264 if (ft->status != FILESTATUS_NOT_ACCEPTED) 1264 if (ft->status != FILESTATUS_NOT_ACCEPTED)
1265 return -5; 1265 return -5;
1266 1266
1267 if (position > ft->size) { 1267 if (position >= ft->size) {
1268 return -6; 1268 return -6;
1269 } 1269 }
1270 1270
@@ -1569,7 +1569,7 @@ static int handle_filecontrol(Messenger *m, int32_t friendnumber, uint8_t receiv
1569 return -1; 1569 return -1;
1570 } 1570 }
1571 1571
1572 /* seek can only be sent by the receiver to seek before resuming broken tranfers. */ 1572 /* seek can only be sent by the receiver to seek before resuming broken transfers. */
1573 if (ft->status != FILESTATUS_NOT_ACCEPTED || !receive_send) { 1573 if (ft->status != FILESTATUS_NOT_ACCEPTED || !receive_send) {
1574 return -1; 1574 return -1;
1575 } 1575 }
@@ -1577,7 +1577,7 @@ static int handle_filecontrol(Messenger *m, int32_t friendnumber, uint8_t receiv
1577 memcpy(&position, data, sizeof(position)); 1577 memcpy(&position, data, sizeof(position));
1578 net_to_host((uint8_t *) &position, sizeof(position)); 1578 net_to_host((uint8_t *) &position, sizeof(position));
1579 1579
1580 if (position > ft->size) { 1580 if (position >= ft->size) {
1581 return -1; 1581 return -1;
1582 } 1582 }
1583 1583
@@ -2128,6 +2128,11 @@ static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len)
2128 file_data = data + 1; 2128 file_data = data + 1;
2129 } 2129 }
2130 2130
2131 /* Prevent more data than the filesize from being passed to clients. */
2132 if ((ft->transferred + file_data_length) > ft->size) {
2133 file_data_length = ft->size - ft->transferred;
2134 }
2135
2131 if (m->file_filedata) 2136 if (m->file_filedata)
2132 (*m->file_filedata)(m, i, real_filenumber, position, file_data, file_data_length, m->file_filedata_userdata); 2137 (*m->file_filedata)(m, i, real_filenumber, position, file_data, file_data_length, m->file_filedata_userdata);
2133 2138