Skip to content

Commit 5283a6c

Browse files
thiagomacieiraThe Qt Project
authored andcommitted
Disable hash seeding for bootstrapped tools
Any bootstrapped tool is a development tool, by definition. So the effects of seeding the hash with a random number can cause the same source input to produce different binary results, which can throw some caching tools into disarray (like the Open Build System). There should be minimal fall out from the reduced protection against DoS. Since those are only development tools, "specially crafted" input implies the developer is DoS'ing him/herself. Note: the change to qhash.cpp applies to moc and rcc, which are always bootstrapped. Change-Id: I061ab52036e40627c0703f1bf881455cbf848f43 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com> Reviewed-by: hjk <hjk121@nokiamail.com>
1 parent 1b03163 commit 5283a6c

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

src/corelib/tools/qhash.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,13 @@ uint qHash(QLatin1String key, uint seed) Q_DECL_NOTHROW
222222
*/
223223
static uint qt_create_qhash_seed()
224224
{
225+
uint seed = 0;
226+
227+
#ifndef QT_BOOTSTRAPPED
225228
QByteArray envSeed = qgetenv("QT_HASH_SEED");
226229
if (!envSeed.isNull())
227230
return envSeed.toUInt();
228231

229-
uint seed = 0;
230-
231232
#ifdef Q_OS_UNIX
232233
int randomfd = qt_safe_open("/dev/urandom", O_RDONLY);
233234
if (randomfd == -1)
@@ -254,17 +255,16 @@ static uint qt_create_qhash_seed()
254255
seed ^= timestamp;
255256
seed ^= (timestamp >> 32);
256257

257-
#ifndef QT_BOOTSTRAPPED
258258
quint64 pid = QCoreApplication::applicationPid();
259259
seed ^= pid;
260260
seed ^= (pid >> 32);
261-
#endif // QT_BOOTSTRAPPED
262261

263262
quintptr seedPtr = reinterpret_cast<quintptr>(&seed);
264263
seed ^= seedPtr;
265264
#if QT_POINTER_SIZE == 8
266265
seed ^= (seedPtr >> 32);
267266
#endif
267+
#endif // QT_BOOTSTRAPPED
268268

269269
return seed;
270270
}

src/tools/qdoc/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,13 +542,15 @@ static void processQdocconfFile(const QString &fileName)
542542
Generator::debugSegfault("qdoc finished!");
543543
}
544544

545+
extern Q_CORE_EXPORT QBasicAtomicInt qt_qhash_seed;
545546
QT_END_NAMESPACE
546547

547548
int main(int argc, char **argv)
548549
{
549550
QT_USE_NAMESPACE
550551

551552
#ifndef QT_BOOTSTRAPPED
553+
qt_qhash_seed.testAndSetRelaxed(-1, 0); // set the hash seed to 0 if it wasn't set yet
552554
QCoreApplication app(argc, argv);
553555
#endif
554556

src/tools/uic/main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,12 @@
5252
#include <qcommandlineparser.h>
5353

5454
QT_BEGIN_NAMESPACE
55+
extern Q_CORE_EXPORT QBasicAtomicInt qt_qhash_seed;
5556

5657
int runUic(int argc, char *argv[])
5758
{
59+
qt_qhash_seed.testAndSetRelaxed(-1, 0); // set the hash seed to 0 if it wasn't set yet
60+
5861
QCoreApplication app(argc, argv);
5962
QCoreApplication::setApplicationVersion(QString::fromLatin1(QT_VERSION_STR));
6063

0 commit comments

Comments
 (0)