From 875af11d027623082f082138ddc69f11ac59b9bf Mon Sep 17 00:00:00 2001 From: pierre Date: Thu, 10 Jan 2019 12:22:58 +0000 Subject: [PATCH] Merge of commits 39916, 39925 and 39963 ------------------------------------------------------------------------ r39916 | yury | 2018-10-12 14:43:17 +0000 (Fri, 12 Oct 2018) | 1 line * Fixed checks for exceeding limit of locals space. Prevent range and overflow errors during the checks. Introduced the MaxLocalsSize constant which provides the maximum possible size of locals space (stack frame) depending of bitness of a cpu. ------------------------------------------------------------------------ --- Merging r39916 into '.': U compiler/tgobj.pas U compiler/globtype.pas --- Recording mergeinfo for merge of r39916 into '.': U . ------------------------------------------------------------------------ r39925 | pierre | 2018-10-13 12:00:31 +0000 (Sat, 13 Oct 2018) | 1 line Set MaxLocalsSize according to address size not register size ------------------------------------------------------------------------ --- Merging r39925 into '.': G compiler/globtype.pas --- Recording mergeinfo for merge of r39925 into '.': G . ------------------------------------------------------------------------ r39963 | yury | 2018-10-17 19:12:27 +0000 (Wed, 17 Oct 2018) | 1 line * Fixed range check errors. ------------------------------------------------------------------------ --- Merging r39963 into '.': G compiler/tgobj.pas --- Recording mergeinfo for merge of r39963 into '.': G . git-svn-id: branches/fixes_3_2@40834 - --- compiler/globtype.pas | 8 ++++++++ compiler/tgobj.pas | 24 +++++++++++++++--------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/compiler/globtype.pas b/compiler/globtype.pas index 7d23464d57..edb37a2e75 100644 --- a/compiler/globtype.pas +++ b/compiler/globtype.pas @@ -87,6 +87,14 @@ interface AIntBits = 8; {$endif cpu8bitalu} + { Maximum possible size of locals space (stack frame) } + Const +{$if defined(cpu16bitaddr)} + MaxLocalsSize = High(PUint); +{$else} + MaxLocalsSize = High(longint) - 15; +{$endif} + Type PAWord = ^AWord; PAInt = ^AInt; diff --git a/compiler/tgobj.pas b/compiler/tgobj.pas index 3089d406e7..016843a3c6 100644 --- a/compiler/tgobj.pas +++ b/compiler/tgobj.pas @@ -274,6 +274,11 @@ implementation freetype:=Used2Free[temptype]; if freetype=tt_none then internalerror(200208201); + if size>MaxLocalsSize then + begin + CGMessage(cg_e_localsize_too_big); + size:=0; // Prevent further range check errors + end; size:=align(size,alignment); { First check the tmpfreelist, but not when we don't want to reuse an already allocated block } @@ -417,29 +422,30 @@ implementation tl^.temptype:=temptype; tl^.def:=def; -{$push} -{$r-} -{$warn 6018 off} -{$warn 4044 off} { Extend the temp } if direction=-1 then begin - if qword(align(-lasttemp-alignmismatch,alignment))+size+alignmismatch>high(tl^.pos) then - CGMessage(cg_e_localsize_too_big); + if Int64(align(-lasttemp-alignmismatch,alignment))+size+alignmismatch>MaxLocalsSize then + begin + CGMessage(cg_e_localsize_too_big); + size:=0; // Prevent further range check errors + end; lasttemp:=(-align(-lasttemp-alignmismatch,alignment))-size-alignmismatch; tl^.pos:=lasttemp; end else begin tl^.pos:=align(lasttemp+alignmismatch,alignment)-alignmismatch; - if qword(tl^.pos)+size>high(tl^.pos) then - CGMessage(cg_e_localsize_too_big); + if Int64(tl^.pos)+size>MaxLocalsSize then + begin + CGMessage(cg_e_localsize_too_big); + size:=0; // Prevent further range check errors + end; lasttemp:=tl^.pos+size; end; {$ifdef EXTDEBUG} Comment(V_Note,'tgobj: (AllocTemp) lasttemp set to '+tostr(lasttemp)); {$endif} -{$pop} tl^.fini:=fini; tl^.alignment:=alignment; tl^.size:=size;