basic/qa/basic_coverage/test_like.bas | 10 ++++++++++ basic/source/runtime/runtime.cxx | 10 ++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-)
New commits: commit 0f23205b390085be25377ff82c1452462e8149bb Author: Mike Kaganski <[email protected]> AuthorDate: Thu Oct 30 17:38:27 2025 +0500 Commit: Christian Lohmaier <[email protected]> CommitDate: Tue Nov 4 13:17:27 2025 +0100 tdf#169147: handle errors creating icu::RegexMatcher Regression after commit 38f731ff67142a423aa6f46dc3e92d094f86ffb1 (tdf#160478: fix Basic LIKE operator, 2024-04-02). Change-Id: I4fae01e56cb91d54adba54c3787f576f60f8b1f0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193202 Reviewed-by: Mike Kaganski <[email protected]> Tested-by: Jenkins (cherry picked from commit 3ab2560526ba7b745889cf509241ff17d0638cc2) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193221 Reviewed-by: Xisco Fauli <[email protected]> Reviewed-by: Christian Lohmaier <[email protected]> Tested-by: Christian Lohmaier <[email protected]> Tested-by: Ilmari Lauhakangas <[email protected]> diff --git a/basic/qa/basic_coverage/test_like.bas b/basic/qa/basic_coverage/test_like.bas index 2d018bf64f01..3e7d049d081f 100644 --- a/basic/qa/basic_coverage/test_like.bas +++ b/basic/qa/basic_coverage/test_like.bas @@ -34,8 +34,18 @@ Sub verify_testLike() TestUtil.AssertEqual("a*b" Like "a [*]b", False, "Like9") TestUtil.AssertEqual("axxxxxb" Like "a [*]b", False, "Like10") TestUtil.AssertEqual("a [xyz" Like "a [[]*", True, "Like11") + ' Invalid pattern + Dim caughtError As Integer + On Error GoTo expectedErrorHandler + TestUtil.AssertEqual("a [xyz" Like "a [*", 42, "") ' Like must fail, will not reach AssertEqual + TestUtil.AssertEqual(caughtError, 93, "tdf#169147") ' Invalid string pattern Exit Sub + +expectedErrorHandler: + caughtError = Err + Resume Next + errorHandler: TestUtil.ReportErrorHandler("verify_testLike", Err, Error$, Erl) End Sub diff --git a/basic/source/runtime/runtime.cxx b/basic/source/runtime/runtime.cxx index 9650e77ae520..ae48fc113824 100644 --- a/basic/source/runtime/runtime.cxx +++ b/basic/source/runtime/runtime.cxx @@ -1527,13 +1527,13 @@ void SbiRuntime::StepLIKE() { bTextMode = IsImageFlag( SbiImageFlags::COMPARETEXT ); } - sal_uInt32 searchFlags = UREGEX_UWORD | UREGEX_DOTALL; // Dot matches newline + uint32_t searchFlags = UREGEX_UWORD | UREGEX_DOTALL; // Dot matches newline if( bTextMode ) { searchFlags |= UREGEX_CASE_INSENSITIVE; } - static sal_uInt32 cachedSearchFlags = 0; + static uint32_t cachedSearchFlags = 0; static OUString cachedRegex; static std::optional<icu::RegexMatcher> oRegexMatcher; UErrorCode nIcuErr = U_ZERO_ERROR; @@ -1544,6 +1544,12 @@ void SbiRuntime::StepLIKE() icu::UnicodeString sRegex(false, reinterpret_cast<const UChar*>(cachedRegex.getStr()), cachedRegex.getLength()); oRegexMatcher.emplace(sRegex, cachedSearchFlags, nIcuErr); + if (U_FAILURE(nIcuErr)) + { + // Bad regex; oRegexMatcher has no pattern - would crash in RegexMatcher::reset + oRegexMatcher.reset(); + return Error(ERRCODE_BASIC_BAD_PATTERN); + } } icu::UnicodeString sSource(false, reinterpret_cast<const UChar*>(value.getStr()),
