From 65e977f062717aa3e77803c7f4a0194c27fa4cd0 Mon Sep 17 00:00:00 2001 From: Jamie Reece Wilson Date: Sun, 17 Nov 2024 00:53:41 +0000 Subject: [PATCH] [*] Harden Qt6.7 (2023/11) Change-Id: Ibf3e7161e31418e4fbcddfdd3f7d5c99ba5a82b3 --- src/corelib/kernel/qcoreapplication.cpp | 4 +- src/widgets/kernel/qlayout.cpp | 54 +++++++++++++++---------- 2 files changed, 35 insertions(+), 23 deletions(-) diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index 0b525c81a7..ca2aaaaa1b 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -1133,10 +1133,10 @@ bool QCoreApplication::notifyInternal2(QObject *receiver, QEvent *event) if (!selfRequired) return doNotify(receiver, event); -#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) +//#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) if (threadData->thread.loadRelaxed() != QCoreApplicationPrivate::mainThread()) return false; -#endif +//#endif return self->notify(receiver, event); } diff --git a/src/widgets/kernel/qlayout.cpp b/src/widgets/kernel/qlayout.cpp index 8fcca0c174..e7d58d469b 100644 --- a/src/widgets/kernel/qlayout.cpp +++ b/src/widgets/kernel/qlayout.cpp @@ -545,6 +545,8 @@ void QLayout::widgetEvent(QEvent *e) } break; case QEvent::LayoutRequest: + if (!parent()) + break; if (static_cast(parent())->isVisible()) activate(); break; @@ -579,10 +581,12 @@ int QLayout::totalMinimumHeightForWidth(int w) const int side=0, top=0; if (d->topLevel) { QWidget *parent = parentWidget(); - parent->ensurePolished(); - QWidgetPrivate *wd = parent->d_func(); - side += wd->leftmargin + wd->rightmargin; - top += wd->topmargin + wd->bottommargin; + if (d->topLevel) { + parent->ensurePolished(); + QWidgetPrivate *wd = parent->d_func(); + side += wd->leftmargin + wd->rightmargin; + top += wd->topmargin + wd->bottommargin; + } } int h = minimumHeightForWidth(w - side) + top; #if QT_CONFIG(menubar) @@ -601,10 +605,12 @@ int QLayout::totalHeightForWidth(int w) const int side=0, top=0; if (d->topLevel) { QWidget *parent = parentWidget(); - parent->ensurePolished(); - QWidgetPrivate *wd = parent->d_func(); - side += wd->leftmargin + wd->rightmargin; - top += wd->topmargin + wd->bottommargin; + if (parent) { + parent->ensurePolished(); + QWidgetPrivate *wd = parent->d_func(); + side += wd->leftmargin + wd->rightmargin; + top += wd->topmargin + wd->bottommargin; + } } int h = heightForWidth(w - side) + top; #if QT_CONFIG(menubar) @@ -623,10 +629,12 @@ QSize QLayout::totalMinimumSize() const int side=0, top=0; if (d->topLevel) { QWidget *pw = parentWidget(); - pw->ensurePolished(); - QWidgetPrivate *wd = pw->d_func(); - side += wd->leftmargin + wd->rightmargin; - top += wd->topmargin + wd->bottommargin; + if (pw) { + pw->ensurePolished(); + QWidgetPrivate *wd = pw->d_func(); + side += wd->leftmargin + wd->rightmargin; + top += wd->topmargin + wd->bottommargin; + } } QSize s = minimumSize(); @@ -646,10 +654,12 @@ QSize QLayout::totalSizeHint() const int side=0, top=0; if (d->topLevel) { QWidget *pw = parentWidget(); - pw->ensurePolished(); - QWidgetPrivate *wd = pw->d_func(); - side += wd->leftmargin + wd->rightmargin; - top += wd->topmargin + wd->bottommargin; + if (pw) { + pw->ensurePolished(); + QWidgetPrivate *wd = pw->d_func(); + side += wd->leftmargin + wd->rightmargin; + top += wd->topmargin + wd->bottommargin; + } } QSize s = sizeHint(); @@ -671,10 +681,12 @@ QSize QLayout::totalMaximumSize() const int side=0, top=0; if (d->topLevel) { QWidget *pw = parentWidget(); - pw->ensurePolished(); - QWidgetPrivate *wd = pw->d_func(); - side += wd->leftmargin + wd->rightmargin; - top += wd->topmargin + wd->bottommargin; + if (pw) { + pw->ensurePolished(); + QWidgetPrivate *wd = pw->d_func(); + side += wd->leftmargin + wd->rightmargin; + top += wd->topmargin + wd->bottommargin; + } } QSize s = maximumSize(); @@ -972,7 +984,7 @@ void QLayout::update() QLayout *layout = this; while (layout && layout->d_func()->activated) { layout->d_func()->activated = false; - if (layout->d_func()->topLevel) { + if (layout->d_func()->topLevel && layout->parent()) { Q_ASSERT(layout->parent()->isWidgetType()); QWidget *mw = static_cast(layout->parent()); if (mw) { /*we always validate layout later, implying it can be null. why the fuck were the Qt devs copying the [~volatile~] parent multiple times and using it without a check?