Skip to content

Commit cd468b8

Browse files
committed
fix: Make sure we null terminate and filter file names
The filename is currently null terminated by toxcore before being passed to this callback, but this is a happy accident and should not be relied upon.
1 parent 510d648 commit cd468b8

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/windows.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,11 +364,15 @@ void on_file_recv_control(Tox *tox, uint32_t friendnumber, uint32_t filenumber,
364364
}
365365

366366
void on_file_recv(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint32_t kind, uint64_t file_size,
367-
const uint8_t *filename, size_t filename_length, void *userdata)
367+
const uint8_t *string, size_t length, void *userdata)
368368
{
369369
Toxic *toxic = (Toxic *) userdata;
370370
Windows *windows = toxic->windows;
371371

372+
char filename[MAX_STR_SIZE + 1];
373+
length = copy_tox_str(filename, sizeof(filename), (const char *) string, length);
374+
filter_string(filename, length, false);
375+
372376
/* We don't care about receiving avatars */
373377
if (kind != TOX_FILE_KIND_DATA) {
374378
tox_file_control(tox, friendnumber, filenumber, TOX_FILE_CONTROL_CANCEL, NULL);
@@ -379,8 +383,7 @@ void on_file_recv(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint32_t
379383
ToxWindow *w = windows->list[i];
380384

381385
if (w->onFileRecv != NULL) {
382-
w->onFileRecv(w, toxic, friendnumber, filenumber, file_size, (const char *) filename,
383-
filename_length);
386+
w->onFileRecv(w, toxic, friendnumber, filenumber, file_size, filename, length);
384387
}
385388
}
386389
}

0 commit comments

Comments
 (0)