summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSlávek Banko <slavek.banko@axis.cz>2022-03-22 02:40:43 +0100
committerSlávek Banko <slavek.banko@axis.cz>2022-03-22 09:04:33 +0100
commit65f3815ede3eb3db71312b5cf4ca32fa58c90c66 (patch)
treefe7fed1281c0c483bc06e0255bd2295929988457
parenta28783fa4801ce0c5455e69bbf118ed9dabef0d8 (diff)
downloadqt3-65f3815ede3eb3db71312b5cf4ca32fa58c90c66.tar.gz
qt3-65f3815ede3eb3db71312b5cf4ca32fa58c90c66.zip
Avoid changes of d->cString for TQString::shared_null to make the value reliable.
This precedes unnecessary allocations, potential use after free and crashes. Signed-off-by: Slávek Banko <slavek.banko@axis.cz> (cherry picked from commit 93058fb0a38cbab73683463cfa571fd622baa980)
-rw-r--r--src/tools/qstring.cpp17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/tools/qstring.cpp b/src/tools/qstring.cpp
index 24fa827..c182447 100644
--- a/src/tools/qstring.cpp
+++ b/src/tools/qstring.cpp
@@ -5991,6 +5991,14 @@ void QString::setSecurityUnPaged(bool lock) {
*/
QCString QString::utf8() const
{
+ if (!d->cString) {
+ d->cString = new QCString;
+ }
+ if(d == shared_null)
+ {
+ return *d->cString;
+ }
+
int l = length();
int rlen = l*3+1;
QCString rstr(rlen);
@@ -6035,11 +6043,8 @@ QCString QString::utf8() const
++ch;
}
rstr.truncate( cursor - (uchar*)rstr.data() );
- if (!d->cString) {
- d->cString = new QCString;
- }
*d->cString = rstr;
- return rstr;
+ return *d->cString;
}
static QChar *addOne(QChar *qch, QString &str)
@@ -6243,6 +6248,10 @@ QCString QString::local8Bit() const
if (!d->cString) {
d->cString = new QCString;
}
+ if(d == shared_null)
+ {
+ return *d->cString;
+ }
#ifdef QT_NO_TEXTCODEC
*d->cString = QCString(latin1());
return *d->cString;