From 75b72e7f69fe208b66dfe969d6bc58857aaaa99f Mon Sep 17 00:00:00 2001 From: aizu-m Date: Tue, 2 Jun 2026 12:31:10 +0530 Subject: [PATCH] xfer: replace directory separator in remote nick by underscore in download filename (#2321) --- CHANGELOG.md | 1 + src/plugins/xfer/xfer-file.c | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7db64baf7..ce026db22 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ - api, relay: fix timing attack on TOTP validation ([GHSA-vhv8-g2r9-cwcc](https://github.com/weechat/weechat/security/advisories/GHSA-vhv8-g2r9-cwcc)) - relay: limit size of decompressed websocket frame with permessage-deflate to prevent memory exhaustion ([GHSA-v2v4-45wm-5cr3](https://github.com/weechat/weechat/security/advisories/GHSA-v2v4-45wm-5cr3)) - relay/weechat: fix empty buffers in client when WeeChat is running on Solaris/illumos +- xfer: replace directory separator in remote nick by underscore in download filename to prevent writing the file outside the download directory ([#2321](https://github.com/weechat/weechat/issues/2321)) - build: fix build on Solaris/illumos (issue #2251) ## Version 4.6.3 (2025-05-11) diff --git a/src/plugins/xfer/xfer-file.c b/src/plugins/xfer/xfer-file.c index cf4663c7e..6e434b096 100644 --- a/src/plugins/xfer/xfer-file.c +++ b/src/plugins/xfer/xfer-file.c @@ -249,7 +249,7 @@ xfer_file_find_suffix (struct t_xfer *xfer) void xfer_file_find_filename (struct t_xfer *xfer) { - char *dir_separator, *path; + char *dir_separator, *path, *nick; struct t_hashtable *options; if (!XFER_IS_FILE(xfer->type)) @@ -285,12 +285,20 @@ xfer_file_find_filename (struct t_xfer *xfer) { strcat (xfer->local_filename, dir_separator); } - free (dir_separator); if (weechat_config_boolean (xfer_config_file_use_nick_in_filename)) { - strcat (xfer->local_filename, xfer->remote_nick); + /* + * the remote nick comes from the server and can contain a directory + * separator: replace it so the nick cannot make the file be written + * outside the download directory + */ + nick = (dir_separator) ? + weechat_string_replace (xfer->remote_nick, dir_separator, "_") : NULL; + strcat (xfer->local_filename, (nick) ? nick : xfer->remote_nick); + free (nick); strcat (xfer->local_filename, "."); } + free (dir_separator); strcat (xfer->local_filename, xfer->filename); free (path);