From 067036c7ef2e6e54fa7ea4913ebc337a9aed55d9 Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Sat, 20 Mar 2010 22:32:57 +0000 Subject: [PATCH] Make regular expression safe against huge length/set attributes of column types. Fixes issue #1786. --- source/helpers.pas | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/source/helpers.pas b/source/helpers.pas index 64bdd50d..cc0c0718 100644 --- a/source/helpers.pas +++ b/source/helpers.pas @@ -11,7 +11,7 @@ interface uses Classes, SysUtils, Graphics, GraphUtil, ClipBrd, Dialogs, Forms, Controls, ComCtrls, ShellApi, CheckLst, Windows, Contnrs, ShlObj, ActiveX, VirtualTrees, SynRegExpr, Messages, - Registry, SynEditHighlighter, DateUtils, Generics.Collections, AnsiStrings, + Registry, SynEditHighlighter, DateUtils, Generics.Collections, StrUtils, AnsiStrings, mysql_connection, mysql_structures; type @@ -2820,13 +2820,18 @@ begin rx := TRegExpr.Create; rx.ModifierS := False; rx.ModifierM := True; - rx.Expression := '^\s+[`"]([^`"]+)[`"]\s(\w+)(.*)'; + rx.Expression := '^\s+[`"]([^`"]+)[`"]\s(\w+)'; rxCol := TRegExpr.Create; rxCol.ModifierI := True; if rx.Exec(CreateTable) then while true do begin if not Assigned(Columns) then break; - ColSpec := rx.Match[3]; + ColSpec := ''; + for i:=rx.MatchPos[2]+rx.MatchLen[2] to Length(CreateTable) do begin + if CharInSet(CreateTable[i], [#13, #10]) then + break; + ColSpec := ColSpec + CreateTable[i]; + end; // Strip trailing comma if (ColSpec <> '') and (ColSpec[Length(ColSpec)] = ',') then