From 49c3e5d553ee8c98761671e62a3b709873605374 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ust=C3=BB=C5=BEanin?= Date: Sat, 25 Sep 2021 11:55:57 +0300 Subject: [PATCH] UDL lexer: fix potential infinite loop Fixed a condition in a loop which is always true (unsigned >= 0) and can potentially turn the loop infinite. And removed a check after the loop which now is also always false. Close #10597 --- scintilla/lexers/LexUser.cxx | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/scintilla/lexers/LexUser.cxx b/scintilla/lexers/LexUser.cxx index 8bedc6196..a133a27db 100644 --- a/scintilla/lexers/LexUser.cxx +++ b/scintilla/lexers/LexUser.cxx @@ -786,20 +786,20 @@ static inline void ReColoringCheck(Sci_PositionU & startPos, int & nestedLevel, int & isCommentLine, bool & isInComment, Accessor & styler, vector & lastNestedGroup, vector & nestedVector, /* vector & foldVector, */ int & continueCommentBlock) { - // re-coloring always starts at line beginning !! - - // special exception for multipart keywords - initStyle = styler.StyleAt(startPos-1); // check style of previous new line character - if ( (initStyle >= SCE_USER_STYLE_KEYWORD1 && initStyle < (SCE_USER_STYLE_KEYWORD1+SCE_USER_TOTAL_KEYWORD_GROUPS)) // keywords1-8 - || initStyle == SCE_USER_STYLE_FOLDER_IN_COMMENT - || initStyle == SCE_USER_STYLE_FOLDER_IN_CODE2 ) + if (startPos > 0) { - // we are in middle of multi-part keyword that contains newline characters, go back until current style ends - while (startPos >= 0 && styler.StyleAt(--startPos) == initStyle); - } + // re-coloring always starts at line beginning !! - if (static_cast(startPos) < 0) - startPos = 0; + // special exception for multipart keywords + initStyle = styler.StyleAt(startPos-1); // check style of previous new line character + if ( (initStyle >= SCE_USER_STYLE_KEYWORD1 && initStyle < (SCE_USER_STYLE_KEYWORD1+SCE_USER_TOTAL_KEYWORD_GROUPS)) // keywords1-8 + || initStyle == SCE_USER_STYLE_FOLDER_IN_COMMENT + || initStyle == SCE_USER_STYLE_FOLDER_IN_CODE2 ) + { + // we are in middle of multi-part keyword that contains newline characters, go back until current style ends + while (startPos > 0 && styler.StyleAt(--startPos) == initStyle); + } + } if (startPos > 0) { @@ -808,8 +808,6 @@ static inline void ReColoringCheck(Sci_PositionU & startPos, int & nestedLevel, do { ch = styler.SafeGetCharAt(--startPos); - if (startPos == -1) - startPos = 0; } while(ch != '\r' && ch != '\n' && startPos > 0);