Remove unnecessary copy from clipboard_get_files()

The routine clipboard_get_files() parses a potentially long string,
and copies portions of it into a temporary buffer. This buffer is then
passed to clipboard_get_file() as pointer + length;

The buffer is inadequately sized for very long filenames which may
approach XFS_MAXFILENAMELEN in length. This can cause chansrv to fail
when the user copies such filenames.

It turns out the buffer is unnecessary, as the filenames can be
passed directly into clipboard_get_file() from the source string,
using pointer + length. This avoids the length limitation entirely.
This commit is contained in:
matt335672 2024-08-01 12:24:07 +01:00
parent c3f7eec4f5
commit 34b5582460

View File

@ -285,37 +285,38 @@ clipboard_get_file(const char *file, int bytes)
}
/*****************************************************************************/
/*
* Calls clipboard_get_file() for each filename in a list.
*
* List items are separated by line terminators. Blank items are ignored */
static int
clipboard_get_files(const char *files, int bytes)
{
int index;
int file_index;
char file[512];
const char *start = files;
const char *end = files + bytes;
const char *p;
file_index = 0;
for (index = 0; index < bytes; index++)
for (p = start ; p < end ; ++p)
{
if (files[index] == '\n' || files[index] == '\r')
if (*p == '\n' || *p == '\r')
{
if (file_index > 0)
{
if (clipboard_get_file(file, file_index) == 0)
/* Skip zero-length files (which might be caused by
* multiple line terminators */
if (p > start)
{
/* Get file. Errors are logged */
(void)clipboard_get_file(start, p - start);
}
file_index = 0;
/* Move the start of filename pointer to either 'end', or
* the next character which will either be a filename or
* another terminator */
start = p + 1;
}
}
else
if (end > start)
{
file[file_index] = files[index];
file_index++;
}
}
if (file_index > 0)
{
if (clipboard_get_file(file, file_index) == 0)
{
}
(void)clipboard_get_file(start, end - start);
}
if (g_files_list->count < 1)
{