Critical BUGFIX: md5 bug

This commit is contained in:
notify 2023-04-15 13:42:11 +08:00
parent ce09673dcc
commit a65c3d8c85
2 changed files with 27 additions and 25 deletions

View File

@ -193,30 +193,13 @@ void Server::processRequest(const QByteArray &msg) {
QJsonArray arr = String2Json(doc[3].toString()).array();
if (md5 != arr[2].toString()) {
QJsonArray body;
body << -2;
body << (Router::TYPE_NOTIFICATION | Router::SRC_SERVER |
Router::DEST_CLIENT);
body << "ErrorMsg";
body << "MD5 check failed!";
client->send(JsonArray2Bytes(body));
body.removeLast();
body.removeLast();
body << "UpdatePackage";
body << Pacman->getPackSummary();
client->send(JsonArray2Bytes(body));
client->disconnectFromHost();
return;
}
handleNameAndPassword(client, arr[0].toString(), arr[1].toString());
handleNameAndPassword(client, arr[0].toString(), arr[1].toString(),
arr[2].toString());
}
void Server::handleNameAndPassword(ClientSocket *client, const QString &name,
const QString &password) {
const QString &password,
const QString &md5_str) {
// First check the name and password
// Matches a string that does not contain special characters
static QRegularExpression nameExp("['\";#]+|(--)|(/\\*)|(\\*/)|(--\\+)");
@ -236,6 +219,25 @@ void Server::handleNameAndPassword(ClientSocket *client, const QString &name,
decrypted_pw = "\xFF";
}
if (md5 != md5_str) {
QJsonArray body;
body << -2;
body << (Router::TYPE_NOTIFICATION | Router::SRC_SERVER |
Router::DEST_CLIENT);
body << "ErrorMsg";
body << "MD5 check failed!";
client->send(JsonArray2Bytes(body));
body.removeLast();
body.removeLast();
body << "UpdatePackage";
body << Pacman->getPackSummary();
client->send(JsonArray2Bytes(body));
client->disconnectFromHost();
return;
}
bool passed = false;
QString error_msg;
QJsonArray result;

View File

@ -19,8 +19,8 @@ public:
bool listen(const QHostAddress &address = QHostAddress::Any,
ushort port = 9527u);
void createRoom(ServerPlayer *owner, const QString &name,
int capacity, const QByteArray &settings = "{}");
void createRoom(ServerPlayer *owner, const QString &name, int capacity,
const QByteArray &settings = "{}");
Room *findRoom(int id) const;
Room *lobby() const;
@ -61,8 +61,8 @@ private:
sqlite3 *db;
QString md5;
void handleNameAndPassword(ClientSocket *client,
const QString &name, const QString &password);
void handleNameAndPassword(ClientSocket *client, const QString &name,
const QString &password, const QString &md5_str);
};
extern Server *ServerInstance;