Skip to content

Commit

Permalink
Add position check to avoid endless loop
Browse files Browse the repository at this point in the history
If a RegEx expression or function fails to successfully parse a token, we don't want to end up in a loop. #442
  • Loading branch information
joyfullservice committed Sep 26, 2023
1 parent 43a5d84 commit cff400b
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Version Control.accda.src/modules/clsSqlFormatter.cls
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit cff400b

Please sign in to comment.