1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

fix(history): Strictly check public_key during database upgrade

Text comparisons in SQL are not case sensitive. Since we want to use this check
to specifically check for case mismatch, cast to blob which then does an exact
comparison.
This commit is contained in:
Anthony Bilinski 2022-03-31 20:16:45 -07:00
parent dc46267833
commit f29570138f
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C

View File

@ -56,8 +56,12 @@ RowId getValidPeerRow(RawDatabase& db, const ChatId& chatId)
{
bool validPeerExists{false};
RowId validPeerRow;
db.execNow(RawDatabase::Query(QStringLiteral("SELECT id FROM peers WHERE public_key='%1';")
.arg(chatId.toString()),
db.execNow(RawDatabase::Query(QStringLiteral("SELECT id FROM peers WHERE CAST(public_key AS BLOB)=?;"),
// Note: The conversion to string then back to binary is intentional to
// ensure we're using the binary presentation of the upper case ASCII
// representation of the binary key, since we want to find the uppercase
// entry or insert it ourselves. This is needed for the dbTo11 upgrade.
{chatId.toString().toUtf8()},
[&](const QVector<QVariant>& row) {
validPeerRow = RowId{row[0].toLongLong()};
validPeerExists = true;