[packages/lftp] Rel 2. Backport upstream torrent/fish/bencode/cwd fixes.

arekm arekm at pld-linux.org
Thu Oct 29 08:40:16 CET 2026


commit c09611ccc0ad14952ad6c79d5af63f591f77a032
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date:   Thu Oct 29 01:31:50 2026 +0100

    Rel 2. Backport upstream torrent/fish/bencode/cwd fixes.

 lftp-bencode-depth.patch       | 69 ++++++++++++++++++++++++++++++
 lftp-cwd-overflow.patch        | 30 +++++++++++++
 lftp-fish-compound-names.patch | 27 ++++++++++++
 lftp-po-linguas.patch          |  7 ++++
 lftp-torrent-path.patch        | 95 ++++++++++++++++++++++++++++++++++++++++++
 lftp.spec                      | 16 ++++++-
 6 files changed, 243 insertions(+), 1 deletion(-)
---
diff --git a/lftp.spec b/lftp.spec
index 6ce85cc..3558288 100644
--- a/lftp.spec
+++ b/lftp.spec
@@ -25,7 +25,7 @@ Summary(pt_BR.UTF-8):	Sofisticado programa de transferência de arquivos (client
 Summary(zh_CN.UTF-8):	lftp 客户端程序
 Name:		lftp
 Version:	4.9.3
-Release:	1
+Release:	2
 License:	GPL v3+
 Group:		Applications/Networking
 Source0:	https://lftp.yar.ru/ftp/%{name}-%{version}.tar.xz
@@ -40,6 +40,15 @@ Patch2:		aliases.patch
 Patch3:		%{name}-pl.po-update.patch
 Patch4:		%{name}-desktop.patch
 Patch5:		gnulib-duplicate-symbols.patch
+# https://github.com/lavv17/lftp/commit/67d5e059dd
+Patch6:		%{name}-torrent-path.patch
+# https://github.com/lavv17/lftp/commit/ca27344982
+Patch7:		%{name}-fish-compound-names.patch
+# https://github.com/lavv17/lftp/commit/2fb63d3691
+Patch8:		%{name}-bencode-depth.patch
+# https://github.com/lavv17/lftp/commit/573d06c046
+Patch9:		%{name}-cwd-overflow.patch
+Patch10:	%{name}-po-linguas.patch
 URL:		http://lftp.tech/
 BuildRequires:	autoconf >= 2.63
 BuildRequires:	automake
@@ -95,6 +104,11 @@ o arquivo FEATURES para uma lista mais detalhada.
 %patch -P3 -p1
 %patch -P4 -p1
 %patch -P5 -p1
+%patch -P6 -p1
+%patch -P7 -p1
+%patch -P8 -p1
+%patch -P9 -p1
+%patch -P10 -p1
 
 %{__rm} po/stamp-po
 
diff --git a/lftp-bencode-depth.patch b/lftp-bencode-depth.patch
new file mode 100644
index 0000000..07b6b69
--- /dev/null
+++ b/lftp-bencode-depth.patch
@@ -0,0 +1,69 @@
+From 2fb63d3691dd79368cbc542f5a7911544a9a42d6 Mon Sep 17 00:00:00 2001
+From: Acts1631 <acts1631kjv at proton.me>
+Date: Thu, 20 Aug 2026 11:58:52 -0400
+Subject: [PATCH] bencode: limit recursive parse depth
+
+Reject excessively nested lists and dictionaries before recursive parsing
+
+can exhaust the client stack when processing peer or tracker data.
+---
+ src/Bencode.cc | 21 +++++++++++++++++----
+ 1 file changed, 17 insertions(+), 4 deletions(-)
+
+diff --git a/src/Bencode.cc b/src/Bencode.cc
+index dbf02aa6e..5925403ee 100644
+--- a/src/Bencode.cc
++++ b/src/Bencode.cc
+@@ -45,8 +45,21 @@ BeNode::BeNode(xmap_p<BeNode> *m)
+    dict.move_here(*m);
+ }
+ 
++static const unsigned MAX_BENCODE_DEPTH=128;
++
++static BeNode *ParseBencode(const char *s,int s_len,int *rest,unsigned depth);
++
+ BeNode *BeNode::Parse(const char *s,int s_len,int *rest)
+ {
++   return ParseBencode(s,s_len,rest,0);
++}
++
++static BeNode *ParseBencode(const char *s,int s_len,int *rest,unsigned depth)
++{
++   if(depth>=MAX_BENCODE_DEPTH) {
++      *rest=s_len;
++      return 0;
++   }
+    if(s_len<2) {
+       *rest=0;
+       return 0;
+@@ -97,7 +110,7 @@ BeNode *BeNode::Parse(const char *s,int s_len,int *rest)
+       while(s_len>1 && *s!='e')
+       {
+ 	 int rest1;
+-	 BeNode *n=Parse(s,s_len,&rest1);
++	 BeNode *n=ParseBencode(s,s_len,&rest1,depth+1);
+ 	 if(!n) {
+ 	    *rest=rest1;
+ 	    return 0;
+@@ -122,18 +135,18 @@ BeNode *BeNode::Parse(const char *s,int s_len,int *rest)
+       while(s_len>1 && *s!='e')
+       {
+ 	 int rest1;
+-	 Ref<BeNode> n(Parse(s,s_len,&rest1));
++	 Ref<BeNode> n(ParseBencode(s,s_len,&rest1,depth+1));
+ 	 if(!n) {
+ 	    *rest=rest1;
+ 	    return 0;
+ 	 }
+-	 if(n->type!=BE_STR) {
++	 if(n->type!=BeNode::BE_STR) {
+ 	    *rest=s_len;
+ 	    return 0;
+ 	 }
+ 	 s+=(s_len-rest1);
+ 	 s_len=rest1;
+-	 BeNode *v=Parse(s,s_len,&rest1);
++	 BeNode *v=ParseBencode(s,s_len,&rest1,depth+1);
+ 	 if(!v) {
+ 	    *rest=rest1;
+ 	    return 0;
diff --git a/lftp-cwd-overflow.patch b/lftp-cwd-overflow.patch
new file mode 100644
index 0000000..17502b0
--- /dev/null
+++ b/lftp-cwd-overflow.patch
@@ -0,0 +1,30 @@
+From 573d06c04674413ba9013673d083d6a110036bd0 Mon Sep 17 00:00:00 2001
+From: Jonas Jelten <jj at sft.lol>
+Date: Thu, 14 Aug 2025 19:00:59 +0200
+Subject: [PATCH] fix stack corruption in `cd` for relative paths due to added
+ prefix length
+
+when the current path is not absolute, the implementation prefixes
+the target directory to change to with ~/
+this is 2 more characters than allocated, hence we write beyond
+the buffer boundary.
+
+in order to fix this, we allocate two more characters for the reconstruction
+buffer, so it can hold a relative path prefixed with ~/ as well.
+---
+ src/ftpclass.cc | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/src/ftpclass.cc b/src/ftpclass.cc
+index 1ea9579f6..eb5d0186b 100644
+--- a/src/ftpclass.cc
++++ b/src/ftpclass.cc
+@@ -651,7 +651,7 @@ int Ftp::SendCWD(const char *path,const char *path_url,Expect::expect_t c)
+       }
+    } else {
+       char *path1=alloca_strdup(path); // to split it
+-      char *path2=alloca_strdup(path); // to re-assemble
++      char *path2=alloca_strdup2(path, 2); // to re-assemble + add space for potential ~/ prefix
+       if(AbsolutePath(path)) {
+ 	 if(real_cwd && !strncmp(real_cwd,path,real_cwd.length())
+ 	 && path[real_cwd.length()]=='/') {
diff --git a/lftp-fish-compound-names.patch b/lftp-fish-compound-names.patch
new file mode 100644
index 0000000..09e47b8
--- /dev/null
+++ b/lftp-fish-compound-names.patch
@@ -0,0 +1,27 @@
+From ca273449824f3ad2ca5dbb506346abcb22ac8c05 Mon Sep 17 00:00:00 2001
+From: Acts1631 <acts1631kjv at proton.me>
+Date: Thu, 20 Aug 2026 11:56:37 -0400
+Subject: [PATCH] fish: reject compound names from remote listings
+
+FISH parses remote ls output directly into FileInfo names. Reject
+
+slash-containing names before consumers such as mirror combine them with
+
+local destination paths, preventing remote path traversal.
+---
+ src/Fish.cc | 2 ++
+ 1 file changed, 2 insertions(+)
+
+diff --git a/src/Fish.cc b/src/Fish.cc
+index 868202e62..183357d8a 100644
+--- a/src/Fish.cc
++++ b/src/Fish.cc
+@@ -1179,6 +1179,8 @@ static FileSet *ls_to_FileSet(const char *b,int len)
+ 
+       set->Add(f);
+    }
++   // Remote shell output must not introduce path components into file names.
++   set->ExcludeCompound();
+    return set;
+ }
+ 
diff --git a/lftp-po-linguas.patch b/lftp-po-linguas.patch
new file mode 100644
index 0000000..abba2b1
--- /dev/null
+++ b/lftp-po-linguas.patch
@@ -0,0 +1,7 @@
+gettext >= 1.0 po/Makefile.in.in reads only po/LINGUAS, not ALL_LINGUAS from
+configure.ac; without it no catalogs are built or installed.
+
+--- /dev/null
++++ lftp-4.9.3/po/LINGUAS
+@@ -0,0 +1 @@
++de es fr it ja ko pl pt_BR sr ru uk zh_CN zh_TW zh_HK cs
diff --git a/lftp-torrent-path.patch b/lftp-torrent-path.patch
new file mode 100644
index 0000000..04b0c6f
--- /dev/null
+++ b/lftp-torrent-path.patch
@@ -0,0 +1,95 @@
+From 67d5e059ddc2be3f13a8947e81443f1f719c62d1 Mon Sep 17 00:00:00 2001
+From: Acts1631 <acts1631kjv at proton.me>
+Date: Thu, 20 Aug 2026 11:57:56 -0400
+Subject: [PATCH] torrent: validate metadata path components
+
+Reject torrent names and file path components containing separators or
+
+dot components before constructing local output paths. Keep MakePath
+
+defensive so malformed metadata cannot escape the output directory.
+---
+ src/Torrent.cc | 41 ++++++++++++++++++++++++++++++++++-------
+ 1 file changed, 34 insertions(+), 7 deletions(-)
+
+diff --git a/src/Torrent.cc b/src/Torrent.cc
+index 98ec08471..b18af07aa 100644
+--- a/src/Torrent.cc
++++ b/src/Torrent.cc
+@@ -417,6 +417,12 @@ void Torrent::SHA1(const xstring& str,xstring& buf)
+    buf.set_length(SHA1_DIGEST_SIZE);
+ }
+ 
++static bool IsSafeTorrentPathComponent(const xstring& path)
++{
++   return path.length()>0 && !path.eq(".") && !path.eq("..")
++      && path.instr('/')<0 && path.instr('\\')<0;
++}
++
+ void Torrent::ValidatePiece(unsigned p)
+ {
+    const xstring& buf=Torrent::RetrieveBlock(p,0,PieceLength(p));
+@@ -801,6 +807,10 @@ bool Torrent::SetMetadata(const xstring& md)
+       name.truncate();
+       info_hash.hexdump_to(name);
+    }
++   if(!IsSafeTorrentPathComponent(name)) {
++      SetError("Meta-data: invalid name");
++      return false;
++   }
+    Reconfig(0);
+ 
+    BeNode *files=info->lookup("files");
+@@ -827,10 +837,28 @@ bool Torrent::SetMetadata(const xstring& md)
+ 	    SetError("Meta-data: invalid or missing file length");
+ 	    return false;
+ 	 }
+-	 if(!Lookup(files->list[i]->dict,"path",BeNode::BE_LIST)) {
++	 BeNode *path=files->list[i]->lookup("path.utf-8",BeNode::BE_LIST);
++	 void (Torrent::*tr)(BeNode*)const=&Torrent::TranslateStringFromUTF8;
++	 if(!path) {
++	    path=Lookup(files->list[i]->dict,"path",BeNode::BE_LIST);
++	    tr=&Torrent::TranslateString;
++	 }
++	 if(!path || path->list.length()==0) {
+ 	    SetError("Meta-data: file path missing");
+ 	    return false;
+ 	 }
++	 for(int j=0; j<path->list.length(); j++) {
++	    BeNode *component=path->list[j];
++	    if(component->type!=BeNode::BE_STR) {
++	       SetError(xstring::format("Meta-data: invalid `info/files[%d]/path[%d]'",i,j));
++	       return false;
++	    }
++	    (this->*tr)(component);
++	    if(!IsSafeTorrentPathComponent(component->str_lc)) {
++	       SetError(xstring::format("Meta-data: invalid `info/files[%d]/path[%d]'",i,j));
++	       return false;
++	    }
++	 }
+ 	 total_length+=f->num;
+       }
+    }
+@@ -1517,17 +1545,16 @@ const char *Torrent::MakePath(BeNode *p) const
+       tr=&Torrent::TranslateString;
+    }
+    static xstring buf;
+-   buf.set(name);
+-   if(buf.eq("..") || buf[0]=='/') {
+-      buf.set_substr(0,0,"_",1);
+-   }
++   buf.set(IsSafeTorrentPathComponent(name) ? name.get() : "_");
+    for(int i=0; i<path->list.count(); i++) {
+       BeNode *e=path->list[i];
+       if(e->type==BeNode::BE_STR) {
+ 	 (this->*tr)(e);
++	 if(!IsSafeTorrentPathComponent(e->str_lc)) {
++	    buf.append("/_");
++	    continue;
++	 }
+ 	 buf.append('/');
+-	 if(e->str_lc.eq(".."))
+-	    buf.append('_');
+ 	 buf.append(e->str_lc);
+       }
+    }
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/lftp.git/commitdiff/c09611ccc0ad14952ad6c79d5af63f591f77a032



More information about the pld-cvs-commit mailing list