lavv17 / lftp

sophisticated command line file transfer program (ftp, http, sftp, fish, torrent)
http://lftp.yar.ru
GNU General Public License v3.0
1.11k stars 162 forks source link

lftp still crashes with segmentation violation when running "find",after the patch: fill verify_fn in case of cd error; fix #650 #674

Closed Lins-01 closed 2 years ago

Lins-01 commented 2 years ago

I find that i stiil have segmentation violation when twice running "find */." . Can i add a ''if(!verify_fn) MakeVerifyFileName();'' in GetFileInfo.cc , line in 400. ? i test it's ok , but i am not sure Are there any other bad effects in normal execution? so I wonder if I can modify it like this. My ftp server is proftpd or vsftpd .Don't take too long between the two times. I have merge the commit's patch 0ead378c8a19d4c7b86e35265a7f6e878fd63c0d

[root@localhost ~]# lftp ftplins@10.137.16.212
Password:
lftp ftplins@10.137.16.212:~> find */.
find: Access failed: 550 /*: No such file or directory
lftp ftplins@10.137.16.212:/> find */.
Segmentation fault (core dumped)

with debug

[root@localhost ~]# lftp ftplins@10.137.16.212
Password:
lftp ftplins@10.137.16.212:~> debug
lftp ftplins@10.137.16.212:~> find */.
---- Connecting to 10.137.16.212 (10.137.16.212) port 21
<--- 220 FTP Server ready.
---> FEAT
<--- 211-Features:
<---  CLNT
<---  EPRT
<---  EPSV
<---  HOST
<---  LANG zh-CN;en-US;zh-TW
<---  MDTM
<---  MFF modify;UNIX.group;UNIX.mode;
<---  MFMT
<---  MLST modify*;perm*;size*;type*;unique*;UNIX.group*;UNIX.groupname*;UNIX.mode*;UNIX.owner*;UNIX.ownername*;
<---  RANG STREAM
<---  REST STREAM
<---  SIZE
<---  TVFS
<---  UTF8
<--- 211 End
---> AUTH TLS
<--- 500 AUTH not understood
---> CLNT lftp/4.9.2
<--- 200 OK
---> LANG
<--- 200 Using default language en_US.UTF-8
---> OPTS UTF8 ON
<--- 200 UTF8 set to on
---> HOST 10.137.16.212
<--- 220 HOST command successful
---> USER ftplins
<--- 331 Password required for ftplins
---> PASS XXXX
<--- 230 User ftplins logged in
---> OPTS MLST modify;perm;size;type;UNIX.group;UNIX.mode;UNIX.owner;
<--- 200 MLST OPTS modify;perm;size;type;UNIX.group;UNIX.mode;UNIX.owner;
---> PWD
<--- 257 "/" is the current directory
---- CWD path to be sent is `/*'
---> CWD /*
<--- 550 /*: No such file or directory
---> TYPE I
<--- 200 Type set to I
find: Access failed: 550 /*: No such file or directory
lftp ftplins@10.137.16.212:/> find */.
Segmentation fault (core dumped)
[root@localhost ~]#

add ''if(!verify_fn) MakeVerifyFileName();'' in GetFileInfo.cc , line in 400.


[root@localhost ~]# lftp ftplins@10.137.16.212
Password:
lftp ftplins@10.137.16.212:~> find */.
find: Access failed: 550 /*: No such file or directory
lftp ftplins@10.137.16.212:/> find */.
find: Access failed: 550 /*: No such file or directory
lftp ftplins@10.137.16.212:/> find */.
find: Access failed: 550 /*: No such file or directory
lftp ftplins@10.137.16.212:/> find */.
find: Access failed: 550 /*: No such file or directory
lftp ftplins@10.137.16.212:/> find */.
find: Access failed: 550 /*: No such file or directory
lftp ftplins@10.137.16.212:/> find */.
find: Access failed: 550 /*: No such file or directory
lftp ftplins@10.137.16.212:/> find */.
find: Access failed: 550 /*: No such file or directory
lftp ftplins@10.137.16.212:/> find */.
find: Access failed: 550 /*: No such file or directory
lftp ftplins@10.137.16.212:/> find */.
find: Access failed: 550 /*: No such file or directory
lftp ftplins@10.137.16.212:/>

with gdb , i find get_info[0] may be 0x0 lead to segmentation violation

SMTask::ScheduleThis (this=0xaaaacac39c70) at SMTask.cc:211
211        Leave();        // unmark it running and change current.
(gdb) n
213     }
(gdb) c
Continuing.

Breakpoint 1, GetFileInfo::Do (this=0xaaaacac39c70) at GetFileInfo.cc:134
134     {
(gdb) n
138        if(Done())
(gdb) p get_info[0]
$5 = (FileInfo *) 0x0
(gdb) n
134     {
(gdb) n
138        if(Done())
(gdb) n
141        switch(state)
(gdb) n
394           if(session->IsClosed())
(gdb) n
411           res=session->Done();
(gdb) n
412           if(res==FA::IN_PROGRESS)
(gdb) n
415           if(res < 0)
(gdb) n
423           session->Close();
(gdb) n
426              FileInfo *fi=get_info[0];
(gdb) n

Breakpoint 2, FileInfo::HasAny (this=0x0, m=<optimized out>) at FileSet.h:134
134        bool HasAny(unsigned m) const { return defined&m; }
(gdb) p get_info[0]
No symbol "get_info" in current context.
(gdb) bt
#0  FileInfo::HasAny (this=0x0, m=<optimized out>) at FileSet.h:134
#1  GetFileInfo::Do (this=0xaaaacac39c70) at GetFileInfo.cc:427
#2  0x0000ffffbc3872d0 in SMTask::ScheduleThis (this=0xaaaacac39c70) at SMTask.cc:210
#3  0x0000ffffbc387500 in SMTask::Schedule () at SMTask.cc:249
#4  0x0000ffffbc42fcf0 in Job::WaitDone (this=0xaaaacac20f40) at Job.cc:560
#5  0x0000aaaaab947d94 in main (argc=2, argv=0xffffc8adfc78) at lftp.cc:590
(gdb) f 1
#1  GetFileInfo::Do (this=0xaaaacac39c70) at GetFileInfo.cc:427
427              if(!fi->HasAny(fi->SIZE|fi->DATE))
(gdb) p get_info[0]
$6 = (FileInfo *) 0x0
(gdb) n

Program received signal SIGSEGV, Segmentation fault.
0x0000ffffbc3ae640 in FileInfo::HasAny (this=0x0, m=<optimized out>) at FileSet.h:134
134        bool HasAny(unsigned m) const { return defined&m; }
(gdb) p this
$7 = (const FileInfo * const) 0x0
(gdb) bt
#0  0x0000ffffbc3ae640 in FileInfo::HasAny (this=0x0, m=<optimized out>) at FileSet.h:134
#1  GetFileInfo::Do (this=0xaaaacac39c70) at GetFileInfo.cc:427
#2  0x0000ffffbc3872d0 in SMTask::ScheduleThis (this=0xaaaacac39c70) at SMTask.cc:210
#3  0x0000ffffbc387500 in SMTask::Schedule () at SMTask.cc:249
#4  0x0000ffffbc42fcf0 in Job::WaitDone (this=0xaaaacac20f40) at Job.cc:560
#5  0x0000aaaaab947d94 in main (argc=2, argv=0xffffc8adfc78) at lftp.cc:590
(gdb) f 1
#1  GetFileInfo::Do (this=0xaaaacac39c70) at GetFileInfo.cc:427
427              if(!fi->HasAny(fi->SIZE|fi->DATE))
(gdb) p verify_fn
$8 = {<xstring0> = {buf = 0x0}, size = 0, len = 0, static null = {<xstring0> = {buf = 0x0}, size = 0, len = 0,
    static null = <same as static member of an already seen type>}}
(gdb) c
Continuing.

Program terminated with signal SIGSEGV, Segmentation fault.
The program no longer exists.
(gdb) q

This is my new patch to fix the second segfault


Date: Mon, 25 Jul 2022 16:04:03 +0800
Subject: [PATCH] 2

---
 src/GetFileInfo.cc | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/GetFileInfo.cc b/src/GetFileInfo.cc
index b553544..f7af6b4 100644
--- a/src/GetFileInfo.cc
+++ b/src/GetFileInfo.cc
@@ -398,6 +398,13 @@ int GetFileInfo::Do()
          * also serves as a last attempt to see if the file exists--we
          * only get here if everything else thinks the path doesn't exist.
          */
+
+        /* new=============================. */
+        if(!verify_fn)
+                MakeVerifyFileName();
+        /* new============================= */
+
+
         FileInfo *fi=new FileInfo(verify_fn);
         fi->need=need;
         /* We need to do at least one. */
--
2.33.0

~
kircherlike commented 2 years ago

I think this patch is very good and should be merged into the main branch as soon as possible.