Allow file names to be of length 0.

Pointer in callback will be NULL if length is 0.
This commit is contained in:
irungentoo 2015-03-17 13:47:09 -04:00
parent 24c70c9e84
commit e072079620
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98
3 changed files with 9 additions and 11 deletions

View File

@ -1115,9 +1115,6 @@ long int new_filesender(const Messenger *m, int32_t friendnumber, uint32_t file_
if (filename_length > MAX_FILENAME_LENGTH)
return -2;
if (file_type == FILEKIND_AVATAR && filename_length != crypto_hash_sha256_BYTES)
return -2;
uint32_t 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;
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];
memcpy(filename_terminated, data + head_length, filename_length);
filename_terminated[filename_length] = 0;
uint8_t *filename = NULL;
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;
real_filenumber += 1;

View File

@ -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,
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);
return UINT32_MAX;
}

View File

@ -1583,10 +1583,6 @@ typedef enum TOX_ERR_FILE_SEND {
* This client is currently not connected to the friend.
*/
TOX_ERR_FILE_SEND_FRIEND_NOT_CONNECTED,
/**
* Filename length was 0.
*/
TOX_ERR_FILE_SEND_NAME_EMPTY,
/**
* Filename length exceeded 255 bytes.
*/