From cff400b8d7e064818f0af196c16828bcc69ea89e Mon Sep 17 00:00:00 2001 From: joyfullservice Date: Tue, 26 Sep 2023 14:14:57 -0500 Subject: [PATCH] Add position check to avoid endless loop If a RegEx expression or function fails to successfully parse a token, we don't want to end up in a loop. #442 --- Version Control.accda.src/modules/clsSqlFormatter.cls | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Version Control.accda.src/modules/clsSqlFormatter.cls b/Version Control.accda.src/modules/clsSqlFormatter.cls index e50dbfac..5f157a58 100644 --- a/Version Control.accda.src/modules/clsSqlFormatter.cls +++ b/Version Control.accda.src/modules/clsSqlFormatter.cls @@ -430,6 +430,7 @@ Private Sub Tokenize(strSql As String) Const cstrBreakAfter As String = "LIMIT" & ";;;;" Dim strMatch As String + Dim lngLastPos As Long ' Reset collection of token items Set m_colTokens = New Collection @@ -541,6 +542,15 @@ Private Sub Tokenize(strSql As String) End If + ' Make sure we don't get stuck on the same position + If m_lngPos = lngLastPos Then + Log.Error eelError, "Unable tp parse SQL after position " & m_lngPos, ModuleName(Me) & ".Tokenize" + AddToken ttUnknown, GetRange(Len(m_strSql) - m_lngPos) + Exit Do + Else + lngLastPos = m_lngPos + End If + ' Move to next token Loop