From f837b16e3643b563353b00180153ff906de5de11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sl=C3=A1vek=20Banko?= Date: Tue, 22 Mar 2022 02:40:43 +0100 Subject: Avoid changes of d->cString for TQString::shared_null to make the value reliable. This precedes unnecessary allocations, potential use after free and crashes. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Slávek Banko (cherry picked from commit e919ffc1ec291cc393e48ea0b9b2580a7a4f954a) --- src/tools/qstring.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/tools/qstring.cpp b/src/tools/qstring.cpp index e6f9260a..25ec4204 100644 --- a/src/tools/qstring.cpp +++ b/src/tools/qstring.cpp @@ -5991,6 +5991,14 @@ void TQString::setSecurityUnPaged(bool lock) { */ TQCString TQString::utf8() const { + if (!d->cString) { + d->cString = new TQCString; + } + if(d == shared_null) + { + return *d->cString; + } + int l = length(); int rlen = l*3+1; TQCString rstr(rlen); @@ -6035,11 +6043,8 @@ TQCString TQString::utf8() const ++ch; } rstr.truncate( cursor - (uchar*)rstr.data() ); - if (!d->cString) { - d->cString = new TQCString; - } *d->cString = rstr; - return rstr; + return *d->cString; } static TQChar *addOne(TQChar *qch, TQString &str) @@ -6243,6 +6248,10 @@ TQCString TQString::local8Bit() const if (!d->cString) { d->cString = new TQCString; } + if(d == shared_null) + { + return *d->cString; + } #ifdef QT_NO_TEXTCODEC *d->cString = TQCString(latin1()); return *d->cString; -- cgit v1.2.3