mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Allow file names to be of length 0.
Pointer in callback will be NULL if length is 0.
This commit is contained in:
parent
24c70c9e84
commit
e072079620
|
@ -1115,9 +1115,6 @@ long int new_filesender(const Messenger *m, int32_t friendnumber, uint32_t file_
|
||||||
if (filename_length > MAX_FILENAME_LENGTH)
|
if (filename_length > MAX_FILENAME_LENGTH)
|
||||||
return -2;
|
return -2;
|
||||||
|
|
||||||
if (file_type == FILEKIND_AVATAR && filename_length != crypto_hash_sha256_BYTES)
|
|
||||||
return -2;
|
|
||||||
|
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
||||||
for (i = 0; i < MAX_CONCURRENT_FILE_PIPES; ++i) {
|
for (i = 0; i < MAX_CONCURRENT_FILE_PIPES; ++i) {
|
||||||
|
@ -2005,10 +2002,15 @@ static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len)
|
||||||
ft->paused = FILE_PAUSE_NOT;
|
ft->paused = FILE_PAUSE_NOT;
|
||||||
memcpy(ft->id, data + 1 + sizeof(uint32_t) + sizeof(uint64_t), FILE_ID_LENGTH);
|
memcpy(ft->id, data + 1 + sizeof(uint32_t) + sizeof(uint64_t), FILE_ID_LENGTH);
|
||||||
|
|
||||||
/* Force NULL terminate file name. */
|
|
||||||
uint8_t filename_terminated[filename_length + 1];
|
uint8_t filename_terminated[filename_length + 1];
|
||||||
memcpy(filename_terminated, data + head_length, filename_length);
|
uint8_t *filename = NULL;
|
||||||
filename_terminated[filename_length] = 0;
|
|
||||||
|
if (filename_length) {
|
||||||
|
/* Force NULL terminate file name. */
|
||||||
|
memcpy(filename_terminated, data + head_length, filename_length);
|
||||||
|
filename_terminated[filename_length] = 0;
|
||||||
|
filename = filename_terminated;
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t real_filenumber = filenumber;
|
uint32_t real_filenumber = filenumber;
|
||||||
real_filenumber += 1;
|
real_filenumber += 1;
|
||||||
|
|
|
@ -910,7 +910,7 @@ bool tox_file_get_file_id(const Tox *tox, uint32_t friend_number, uint32_t file_
|
||||||
uint32_t tox_file_send(Tox *tox, uint32_t friend_number, uint32_t kind, uint64_t file_size, const uint8_t *file_id,
|
uint32_t tox_file_send(Tox *tox, uint32_t friend_number, uint32_t kind, uint64_t file_size, const uint8_t *file_id,
|
||||||
const uint8_t *filename, size_t filename_length, TOX_ERR_FILE_SEND *error)
|
const uint8_t *filename, size_t filename_length, TOX_ERR_FILE_SEND *error)
|
||||||
{
|
{
|
||||||
if (!filename) {
|
if (filename_length && !filename) {
|
||||||
SET_ERROR_PARAMETER(error, TOX_ERR_FILE_SEND_NULL);
|
SET_ERROR_PARAMETER(error, TOX_ERR_FILE_SEND_NULL);
|
||||||
return UINT32_MAX;
|
return UINT32_MAX;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1583,10 +1583,6 @@ typedef enum TOX_ERR_FILE_SEND {
|
||||||
* This client is currently not connected to the friend.
|
* This client is currently not connected to the friend.
|
||||||
*/
|
*/
|
||||||
TOX_ERR_FILE_SEND_FRIEND_NOT_CONNECTED,
|
TOX_ERR_FILE_SEND_FRIEND_NOT_CONNECTED,
|
||||||
/**
|
|
||||||
* Filename length was 0.
|
|
||||||
*/
|
|
||||||
TOX_ERR_FILE_SEND_NAME_EMPTY,
|
|
||||||
/**
|
/**
|
||||||
* Filename length exceeded 255 bytes.
|
* Filename length exceeded 255 bytes.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue
Block a user