Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable-3.14] Properly check for webdav or dav path in provided host url for cmd.cpp #7301

Merged
merged 3 commits into from
Oct 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/cmd/cmd.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

Check notice on line 1 in src/cmd/cmd.cpp

View workflow job for this annotation

GitHub Actions / build

Run clang-format on src/cmd/cmd.cpp

File src/cmd/cmd.cpp does not conform to Custom style guidelines. (lines 347, 348)
* Copyright (C) by Olivier Goffart <[email protected]>
* Copyright (C) by Klaas Freitag <[email protected]>
* Copyright (C) by Daniel Heule <[email protected]>
Expand All @@ -15,8 +15,7 @@
*/

#include <iostream>
#include <random>
#include <qcoreapplication.h>

Check failure on line 18 in src/cmd/cmd.cpp

View workflow job for this annotation

GitHub Actions / build

src/cmd/cmd.cpp:18:10 [clang-diagnostic-error]

'qcoreapplication.h' file not found
#include <QStringList>
#include <QUrl>
#include <QFile>
Expand Down Expand Up @@ -307,7 +306,7 @@
}
}

int main(int argc, char **argv)

Check warning on line 309 in src/cmd/cmd.cpp

View workflow job for this annotation

GitHub Actions / build

src/cmd/cmd.cpp:309:5 [readability-function-cognitive-complexity]

function 'main' has cognitive complexity of 35 (threshold 25)
{
#ifdef Q_OS_WIN
SetDllDirectory(L"");
Expand Down Expand Up @@ -345,15 +344,18 @@
return EXIT_FAILURE;
}

if (options.target_url.contains("/webdav", Qt::CaseInsensitive) || options.target_url.contains("/dav", Qt::CaseInsensitive)) {
const auto sanitisedTargetUrl = options.target_url.endsWith('/') || options.target_url.endsWith('\\')
? options.target_url.chopped(1)
: options.target_url;
QUrl hostUrl = QUrl::fromUserInput(sanitisedTargetUrl);

Check warning on line 350 in src/cmd/cmd.cpp

View workflow job for this annotation

GitHub Actions / build

src/cmd/cmd.cpp:350:10 [cppcoreguidelines-init-variables]

variable 'hostUrl' is not initialized

if (const auto hostUrlPath = hostUrl.path(); hostUrlPath.contains("/webdav", Qt::CaseInsensitive) || hostUrlPath.contains("/dav", Qt::CaseInsensitive)) {
qWarning("Dav or webdav in server URL.");
std::cerr << "Error! Please specify only the base URL of your host with username and password. Example:" << std::endl
<< "http(s)://username:[email protected]" << std::endl;
<< "https://username:[email protected]" << std::endl;
return EXIT_FAILURE;
}

QUrl hostUrl = QUrl::fromUserInput((options.target_url.endsWith(QLatin1Char('/')) || options.target_url.endsWith(QLatin1Char('\\'))) ? options.target_url.chopped(1) : options.target_url);

// Order of retrieval attempt (later attempts override earlier ones):
// 1. From URL
// 2. From options
Expand Down
Loading