diff options
author | Gregory Mullen (grayhatter) <greg@grayhatter.com> | 2015-11-07 20:36:57 -0800 |
---|---|---|
committer | Gregory Mullen (grayhatter) <greg@grayhatter.com> | 2015-11-07 20:36:57 -0800 |
commit | e1ad6cc8f9a5613439937096b55b476f65a00730 (patch) | |
tree | 9dcf444c993681cc654f0e2874ab66264ec289c6 /toxcore/Messenger.c | |
parent | 3631b460a6b763acda718bb71b7f6a1ee31a3299 (diff) | |
parent | 6a494e2cbdd146bb13185d8220061322661a5f5a (diff) |
Merge remote-tracking branch 'upstream/master' into rm-files
Diffstat (limited to 'toxcore/Messenger.c')
-rw-r--r-- | toxcore/Messenger.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 2ff2ac13..6d45077a 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 | ||
@@ -2240,7 +2245,7 @@ static void connection_status_cb(Messenger *m) | |||
2240 | } | 2245 | } |
2241 | 2246 | ||
2242 | 2247 | ||
2243 | #ifdef LOGGING | 2248 | #ifdef TOX_LOGGER |
2244 | #define DUMPING_CLIENTS_FRIENDS_EVERY_N_SECONDS 60UL | 2249 | #define DUMPING_CLIENTS_FRIENDS_EVERY_N_SECONDS 60UL |
2245 | static time_t lastdump = 0; | 2250 | static time_t lastdump = 0; |
2246 | static char IDString[crypto_box_PUBLICKEYBYTES * 2 + 1]; | 2251 | static char IDString[crypto_box_PUBLICKEYBYTES * 2 + 1]; |
@@ -2316,7 +2321,7 @@ void do_messenger(Messenger *m) | |||
2316 | do_friends(m); | 2321 | do_friends(m); |
2317 | connection_status_cb(m); | 2322 | connection_status_cb(m); |
2318 | 2323 | ||
2319 | #ifdef LOGGING | 2324 | #ifdef TOX_LOGGER |
2320 | 2325 | ||
2321 | if (unix_time() > lastdump + DUMPING_CLIENTS_FRIENDS_EVERY_N_SECONDS) { | 2326 | if (unix_time() > lastdump + DUMPING_CLIENTS_FRIENDS_EVERY_N_SECONDS) { |
2322 | 2327 | ||
@@ -2415,7 +2420,7 @@ void do_messenger(Messenger *m) | |||
2415 | } | 2420 | } |
2416 | } | 2421 | } |
2417 | 2422 | ||
2418 | #endif /* LOGGING */ | 2423 | #endif /* TOX_LOGGER */ |
2419 | } | 2424 | } |
2420 | 2425 | ||
2421 | /* new messenger format for load/save, more robust and forward compatible */ | 2426 | /* new messenger format for load/save, more robust and forward compatible */ |