Skip to content

Commit

Permalink
Remove unnecessary copy from clipboard_get_files()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
matt335672 committed Aug 2, 2024
1 parent c3f7eec commit 34b5582
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions sesman/chansrv/clipboard_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
/* Skip zero-length files (which might be caused by
* multiple line terminators */
if (p > start)
{
if (clipboard_get_file(file, file_index) == 0)
{
}
file_index = 0;
/* Get file. Errors are logged */
(void)clipboard_get_file(start, p - start);
}
}
else
{
file[file_index] = files[index];
file_index++;

/* 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;
}
}
if (file_index > 0)
if (end > start)
{
if (clipboard_get_file(file, file_index) == 0)
{
}
(void)clipboard_get_file(start, end - start);
}
if (g_files_list->count < 1)
{
Expand Down

0 comments on commit 34b5582

Please sign in to comment.