diff --git a/.gitignore b/.gitignore index 5439c79..88f73e0 100644 --- a/.gitignore +++ b/.gitignore @@ -71,3 +71,4 @@ Thumbs.db *.exe +/build diff --git a/QFtpServer/mainwindow.cpp b/QFtpServer/mainwindow.cpp index ab544a8..228375d 100644 --- a/QFtpServer/mainwindow.cpp +++ b/QFtpServer/mainwindow.cpp @@ -6,6 +6,7 @@ #include #include #include +#include MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) diff --git a/QFtpServerCommandLine/main.cpp b/QFtpServerCommandLine/main.cpp index 1d4ca1b..c2435d0 100644 --- a/QFtpServerCommandLine/main.cpp +++ b/QFtpServerCommandLine/main.cpp @@ -3,10 +3,17 @@ #include #include #include +#include QChar getRandomChar() { +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + const int range = 'z'-'a' + 1; + const int randomNumber = QRandomGenerator::global()->bounded(range); + return QChar('a' + randomNumber); +#else return QChar('a' + (qrand()%('z'-'a'))); +#endif } QString getRandomString(int n) @@ -21,9 +28,10 @@ QString getRandomString(int n) int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); - +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // Seed the random numbers. qsrand(QTime::currentTime().msec()); +#endif const QString &userName = getRandomString(3); const QString &password = getRandomString(3); diff --git a/QFtpServerLib/ftpcontrolconnection.cpp b/QFtpServerLib/ftpcontrolconnection.cpp index 7af56e2..e56d8cc 100644 --- a/QFtpServerLib/ftpcontrolconnection.cpp +++ b/QFtpServerLib/ftpcontrolconnection.cpp @@ -15,6 +15,8 @@ #include #include +#include + FtpControlConnection::FtpControlConnection(QObject *parent, QSslSocket *socket, const QString &rootPath, const QString &userName, const QString &password, bool readOnly) : QObject(parent) { @@ -137,7 +139,7 @@ QString FtpControlConnection::toLocalPath(const QString &fileName) const // Note we do this **before** prepending the root path, in order to avoid // "jailbreaking" out of the "chroot". QStringList components; - foreach (const QString &component, localPath.split('/', QString::SkipEmptyParts)) { + foreach (const QString &component, localPath.split('/', Qt::SkipEmptyParts)) { if (component == "..") { if (!components.isEmpty()) { components.pop_back(); @@ -256,10 +258,30 @@ void FtpControlConnection::port(const QString &addressAndPort) // PORT h1,h2,h3,h4,p1,p2 // Get IP and port. + QString hostName; + int port = 0; +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + QRegularExpression exp("\\s*(\\d+,\\d+,\\d+,\\d+),(\\d+),(\\d+)"); + auto match = exp.match(addressAndPort); + if(match.hasMatch()) { + hostName = match.captured(1).replace(',', '.'); + int h = match.captured(2).toInt(); + int l = match.captured(3).toInt(); + port = h * 256 + l; + } +#else QRegExp exp("\\s*(\\d+,\\d+,\\d+,\\d+),(\\d+),(\\d+)"); - exp.indexIn(addressAndPort); - QString hostName = exp.cap(1).replace(',', '.'); - int port = exp.cap(2).toInt() * 256 + exp.cap(3).toInt(); + if (exp.indexIn(addressAndPort) != -1) { + QString hostName = exp.cap(1).replace(',', '.'); + int h = exp.cap(2).toInt(); + int l = exp.cap(3).toInt(); + port = h * 256 + l; + } +#endif + if(hostName.isEmpty()) { + reply("address or port invalid!!!"); + return; + } dataConnection->scheduleConnectToHost(hostName, port, encryptDataConnection); reply("200 Command okay."); }