Skip to content

Commit 5cbfac7

Browse files
committed
libpurple: always use unique filename for incoming file
1 parent e567728 commit 5cbfac7

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

backends/libpurple/main.cpp

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1928,10 +1928,9 @@ static void newXfer(PurpleXfer *xfer) {
19281928
}
19291929
LOG4CXX_INFO(logger, "Accepting " << remote_filename << " from " << w);
19301930
gchar *dirname = g_build_filename(web_dir.c_str(), NULL);
1931-
gchar *filename = g_build_filename(dirname, remote_filename.c_str(), NULL);
19321931
// Uniqifying code taken from Pidgin autoaccept plugin
19331932
/* Split at the first dot, to avoid uniquifying "foo.tar.gz" to "foo.tar-2.gz" */
1934-
name_and_ext = g_strsplit(filename, ".", 2);
1933+
name_and_ext = g_strsplit(remote_filename.c_str(), ".", 2);
19351934
name = name_and_ext[0];
19361935
if (name == NULL)
19371936
{
@@ -1947,24 +1946,14 @@ static void newXfer(PurpleXfer *xfer) {
19471946
{
19481947
ext = g_strdup("");
19491948
}
1950-
/* Make sure the file doesn't exist. Do we want some better checking than this? */
1951-
/* FIXME: There is a race here: if the newly uniquified file name gets created between
1952-
* this g_file_test and the transfer starting, the file created in the meantime
1953-
* will be clobbered. But it's not at all straightforward to fix.
1954-
*/
1955-
while (g_file_test(filename, G_FILE_TEST_EXISTS))
1956-
{
1957-
char *file = g_strdup_printf("%s-%d%s", name, count++, ext);
1958-
g_free(filename);
1959-
filename = g_build_filename(dirname, file, NULL);
1960-
g_free(file);
1961-
}
1962-
1949+
char *file = g_strdup_printf("%s%s", g_uuid_string_random(), ext);
1950+
gchar *filename = g_build_filename(dirname, file, NULL);
19631951
purple_xfer_request_accepted_wrapped(xfer, filename);
19641952
g_strfreev(name_and_ext);
19651953
g_free(ext);
19661954
g_free(dirname);
19671955
g_free(filename);
1956+
g_free(file);
19681957
}
19691958

19701959
static void XferReceiveComplete(PurpleXfer *xfer) {

0 commit comments

Comments
 (0)