Bug 388626 - listFolder() in kio_obexftp handles trailing slashes in url incorrectly when filling m_statMap
Summary: listFolder() in kio_obexftp handles trailing slashes in url incorrectly when ...
Status: RESOLVED FIXED
Alias: None
Product: Bluedevil
Classification: Plasma
Component: kio-obex (show other bugs)
Version: 5.11.5
Platform: openSUSE Linux
: NOR normal
Target Milestone: ---
Assignee: David Rosca
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-01-06 18:07 UTC by a425937
Modified: 2018-01-10 14:28 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In: 5.12.0
Sentry Crash Report:


Attachments
Proposed patch (1.25 KB, patch)
2018-01-09 15:53 UTC, a425937
Details
Patch proposal, with sign off line (1.30 KB, patch)
2018-01-09 17:02 UTC, a425937
Details

Note You need to log in before you can comment on or make changes to this bug.
Description a425937 2018-01-06 18:07:04 UTC
Overview:
After opening a link to an obexftp directory on a phone in dolphin, pasting a file into that directory fails.
Example url: obexftp://00-25-d0-xx-xx-xx/Speicherk./some/directory
Seems to be related to a problem in trailing-slash handling in kioobexftp.cpp
The problem surfaced recently while it was running ok before. I did not dig into why it was covered before (I guess something in dolphin changed).

Steps to Reproduce:
enter e.g. in bash:
dolphin obexftp://00-25-d0-xx-xx-xx/Speicherk./some/directory
paste a file already in clipboard into that directory (Ctrl+V)

Actual Results: 
File does not appear in dolphin GUI in the directory.
syslog shows: e.g.  
obexd[4459]: Transfer(0x563b14ca3c10) Error: Forbidden
Pasted file is also not on the phone.

Expected Results:
File should appear in directory (in dolphin GUI and on phone).

Build Date & Platform:
NAME="openSUSE Tumbleweed"
VERSION="20180103 "
bluedevil5-5.11.5-1.1.x86_64.rpm

Additional Information:
Debugging result:
(bluedevil-5.11.5/src/kio/obexftp/kioobexftp.cpp)
The problem is caused by a failing stat() on the opened directory. This caused
by having a duplicate slash in m_statMap (obexftp://00-25-d0-xx-xx-xx/Speicherk./some//directory).
Short debugging run-thru:
statHelper() is called for "obexftp://00-25-d0-xx-xx-xx/Speicherk./some/directory"
It is not found in m_statMap so a
listFolder(urlUpDir(url), &ok);
is triggered to collect the missing information.
urlUpDir(url) results in "obexftp://00-25-d0-xx-xx-xx/Speicherk./some/"

Within listFolder() for each found directory entry

L464: QUrl statUrl = url;
L465: statUrl.setPath(statUrl.path() + QLatin1Char('/') + item.name());

is called. Results e.g. in "obexftp://00-25-d0-xx-xx-xx/Speicherk./some//directory".

Returned to statHelper() m_statMap does still not contain a result for "obexftp://00-25-d0-xx-xx-xx/Speicherk./some//directory".

So 
L416:  qCWarning(OBEXFTP) << "statMap still does not contains the url!";
is hit. statHelper() returns its result via
L419: statEntry(m_statMap.value(url.toDisplayString()));
... which is empty.

Proposed fix:
change L465 from
 statUrl.setPath(statUrl.path() + QLatin1Char('/') + item.name());
to
 if (statUrl.path().endsWith('/')) {
            statUrl.setPath(statUrl.path() + item.name());
        } else {
            statUrl.setPath(statUrl.path() + QLatin1Char('/') + item.name());
        }

This is e.g. in line with addPathToUrl() in
kio-5.40.0/src/core/copyjob.cpp
Comment 1 a425937 2018-01-06 18:16:20 UTC
Typo ...

Returned to statHelper() m_statMap does still not contain a result for "obexftp://00-25-d0-xx-xx-xx/Speicherk./some//directory".

should read as

Returned to statHelper() m_statMap does still not contain a result for "obexftp://00-25-d0-xx-xx-xx/Speicherk./some/directory".
Comment 2 a425937 2018-01-09 15:53:01 UTC
Created attachment 109766 [details]
Proposed patch
Comment 3 David Rosca 2018-01-09 16:34:57 UTC
I need your full name and email to apply this patch.
Comment 4 a425937 2018-01-09 17:02:32 UTC
Created attachment 109769 [details]
Patch proposal, with sign off line
Comment 5 David Rosca 2018-01-10 14:28:17 UTC
Git commit c9558516ed5ddd8ebf33767cdd22668f53b8154e by David Rosca, on behalf of Ludger Dreier.
Committed on 10/01/2018 at 14:25.
Pushed by drosca into branch 'master'.

kio_obexftp: avoid duplicate slash when storing file stat

Check if url already ends in slash ("/"). Insert slash between folder
name and filename only if folder url does not end in slash.
FIXED-IN: 5.12.0

M  +6    -1    src/kio/obexftp/kioobexftp.cpp

https://commits.kde.org/bluedevil/c9558516ed5ddd8ebf33767cdd22668f53b8154e