diff options
author | Marcus Tillmanns <marcus.tillmanns@qt.io> | 2024-02-01 13:11:14 +0100 |
---|---|---|
committer | Marcus Tillmanns <marcus.tillmanns@qt.io> | 2024-02-04 13:54:18 +0000 |
commit | b50e77e858c89f3ab972de97865bdcdbb6131ffe (patch) | |
tree | fc1dddde27fc9d5898fb1210f620f5a8558e71ed /src/shared | |
parent | f96365194c7b386a631a800819807a1a06334693 (diff) |
ProParser: Guard against OOM
When the pattern for a regular expression is empty, every character
of the source is replaced with a copy of the "after" part of a
"QString::replace(re, after)". If input and output are huge this results
in a bad_alloc. We catch that here.
Fixes: QTCREATORBUG-16957
Change-Id: If512f407a2170d93ae7e4182219d9926945b14de
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/proparser/qmakeevaluator.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/shared/proparser/qmakeevaluator.cpp b/src/shared/proparser/qmakeevaluator.cpp index 0ea6c7f133..36e82bf25a 100644 --- a/src/shared/proparser/qmakeevaluator.cpp +++ b/src/shared/proparser/qmakeevaluator.cpp @@ -877,10 +877,16 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::visitProVariable( QRegularExpression regexp(pattern, case_sense ? QRegularExpression::NoPatternOption : QRegularExpression::CaseInsensitiveOption); - // We could make a union of modified and unmodified values, - // but this will break just as much as it fixes, so leave it as is. - replaceInList(&valuesRef(varName), regexp, replace, global, m_tmp2); - debugMsg(2, "replaced %s with %s", dbgQStr(pattern), dbgQStr(replace)); + try + { + // We could make a union of modified and unmodified values, + // but this will break just as much as it fixes, so leave it as is. + replaceInList(&valuesRef(varName), regexp, replace, global, m_tmp2); + debugMsg(2, "replaced %s with %s", dbgQStr(pattern), dbgQStr(replace)); + } catch (const std::bad_alloc &e) { + qWarning() << "Bad alloc caught in replaceInList:" << e.what(); + return ReturnError; + } } else { ProStringList varVal; if (expandVariableReferences(tokPtr, sizeHint, &varVal, false) == ReturnError) |