Bug 447527

Summary: kioslave crashes when opening an unreadable file in an sftp folder
Product: [Frameworks and Libraries] kio-extras Reporter: Kishore Gopalakrishnan <kishore96>
Component: SFTPAssignee: Plasma Bugs List <plasma-bugs>
Status: RESOLVED FIXED    
Severity: crash CC: asn, Avamander, dennis.lissov, globalunity, nate, pinaraf, sitter
Priority: NOR    
Version: 21.12.0   
Target Milestone: ---   
Platform: Arch Linux   
OS: Linux   
Latest Commit: Version Fixed In: 22.04
Sentry Crash Report:
Attachments: Error dialog (window title is 'Error - Dolphin')

Description Kishore Gopalakrishnan 2021-12-26 08:03:14 UTC
Created attachment 144871 [details]
Error dialog (window title is 'Error - Dolphin')

SUMMARY
kioslave crashes (instead of showing an error message) when I try to open a file (for which my user doesn't have read permission) in an sftp folder.

STEPS TO REPRODUCE
1. ssh to a server
2. echo "test" > test.txt
3. chmod 000 test.txt
4. Open the corresponding folder in Dolphin via sftp and click on test.txt to open it

OBSERVED RESULTS
I get a message saying 'kioslave5 closed unexpectedly'. Dolphin displays an error window with just the address of the host I am connecting to (screenshot attached; the title of the dialog is 'Error - Dolphin').

EXPECTED RESULTS
An error message telling the user that the file is not readable.

SOFTWARE VERSIONS
Operating System: Arch Linux
KDE Plasma Version: 5.23.4
KDE Frameworks Version: 5.89.0
Qt Version: 5.15.2
Kernel Version: 5.15.11-arch2-1 (64-bit)
Graphics Platform: X11

ADDITIONAL INFORMATION (DEBUG TRACES)
Application: kioslave5 (kioslave5), signal: Segmentation fault

[KCrash Handler]
#4  0x00007f47bc4e160e in sftp_close (file=0x0) at /usr/src/debug/libssh-0.9.6/src/sftp.c:1764
#5  0x00007f47c193c053 in operator() (__closure=<synthetic pointer>) at /usr/src/debug/kio-extras-21.12.0/sftp/kio_sftp.cpp:1268
#6  QScopeGuard<SFTPInternal::sftpGet(const QUrl&, KIO::fileoffset_t, int)::<lambda()> >::~QScopeGuard (this=<synthetic pointer>, __in_chrg=<optimized out>) at /usr/include/qt/QtCore/qscopeguard.h:80
#7  SFTPInternal::sftpGet (this=this@entry=0x55a641d4e950, url=..., offset=140724810787288, offset@entry=-1, fd=fd@entry=-1) at /usr/src/debug/kio-extras-21.12.0/sftp/kio_sftp.cpp:1340
#8  0x00007f47c193c4bd in SFTPInternal::get (this=0x55a641d4e950, url=...) at /usr/src/debug/kio-extras-21.12.0/sftp/kio_sftp.cpp:1206
#9  0x00007f47c193c65b in SFTPSlave::get (this=0x7ffd0c5bac90, url=...) at /usr/include/qt/QtCore/qscopedpointer.h:116
#10 0x00007f47c1812c7f in KIO::SlaveBase::dispatch (this=0x7ffd0c5bac90, command=67, data=...) at /usr/src/debug/kio-5.89.0/src/core/slavebase.cpp:1221
#11 0x00007f47c1813496 in KIO::SlaveBase::dispatchLoop (this=0x7ffd0c5bac90) at /usr/src/debug/kio-5.89.0/src/core/slavebase.cpp:335
#12 0x00007f47c193c818 in kdemain (argc=<optimized out>, argv=0x7ffd0c5bad80) at /usr/src/debug/kio-extras-21.12.0/sftp/kio_sftp.cpp:92
#13 0x000055a64111d20a in main (argc=5, argv=0x7ffd0c5baed8) at /usr/src/debug/kio-5.89.0/src/kioslave/kioslave.cpp:141
[Inferior 1 (process 57118) detached]
Comment 1 Harald Sitter 2022-01-04 12:41:00 UTC
@Andreas, shouldn't sftp_close be safe to call with a nullptr?
Comment 2 Harald Sitter 2022-03-03 11:23:05 UTC
*** Bug 451027 has been marked as a duplicate of this bug. ***
Comment 3 Harald Sitter 2022-03-29 11:26:37 UTC
*** Bug 452025 has been marked as a duplicate of this bug. ***
Comment 4 Harald Sitter 2022-04-07 21:54:40 UTC
Git commit ac49e5def4f6a22c868bd34e154cc980248c4419 by Harald Sitter.
Committed on 06/04/2022 at 08:45.
Pushed by ngraham into branch 'release/22.04'.

sftp: guard sftp_close it's not safe to call with nullptrs

M  +4    -2    sftp/kio_sftp.cpp

https://invent.kde.org/network/kio-extras/commit/ac49e5def4f6a22c868bd34e154cc980248c4419
Comment 5 Nate Graham 2022-04-26 16:38:55 UTC
*** Bug 453006 has been marked as a duplicate of this bug. ***