From 478920da0895d8c55827cda8f1d20e1b7fa511ea Mon Sep 17 00:00:00 2001 From: Simon Chenery Date: Tue, 18 Feb 2025 19:55:58 +0100 Subject: [PATCH] Add isEmpty() to avoid possible OUString underflow in HelpSearch.cxx Avoid accessing invalid index -1 if OUString queryStr is empty. It cannot be guaranteed that callers will always pass a non-empty value for queryStr. Change-Id: I759a4caea5d52371467f58bb5b95edbd3ff7d4d6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181850 Tested-by: Ilmari Lauhakangas Reviewed-by: Ilmari Lauhakangas Tested-by: Jenkins --- helpcompiler/source/HelpSearch.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helpcompiler/source/HelpSearch.cxx b/helpcompiler/source/HelpSearch.cxx index 982e672c4573..8e6e8d9ecadf 100644 --- a/helpcompiler/source/HelpSearch.cxx +++ b/helpcompiler/source/HelpSearch.cxx @@ -29,7 +29,7 @@ void HelpSearch::query(OUString const &queryStr, bool captionOnly, const TCHAR* field = captionOnly ? L"caption" : L"content"; - bool isWildcard = queryStr[queryStr.getLength() - 1] == L'*'; + const bool isWildcard = (!queryStr.isEmpty() && queryStr[queryStr.getLength() - 1] == L'*'); std::vector aQueryStr(OUStringToTCHARVec(queryStr)); lucene::search::Query *pQuery; if (isWildcard)