From f0ce562200213cdb6d6fcee59f8c4e9858b8cb7f Mon Sep 17 00:00:00 2001 From: Martin Date: Sun, 2 Apr 2023 20:35:34 +0200 Subject: [PATCH] FpDebug: more range check exceptions / fixed missing begin/end --- components/fpdebug/fpdbgdwarf.pas | 8 ++++++-- components/fpdebug/fpdbgdwarffreepascal.pas | 20 +++++++++++--------- components/fpdebug/fppascalparser.pas | 3 ++- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/components/fpdebug/fpdbgdwarf.pas b/components/fpdebug/fpdbgdwarf.pas index d9cfab14f8..b61faa32c8 100644 --- a/components/fpdebug/fpdbgdwarf.pas +++ b/components/fpdebug/fpdbgdwarf.pas @@ -2599,6 +2599,8 @@ var begin ASubStr := ''; Result := True; + if ALen <= 0 then + exit; t := TypeInfo; if t = nil then @@ -2629,7 +2631,7 @@ begin then ALen := MemManager.MemLimits.MaxStringLen; - {$PUSH}{$Q-} + {$PUSH}{$Q-}{$R-} Addr.Address := Addr.Address + AStartIndex - 1; {$POP} if not ( (MemManager.SetLength(ASubStr, ALen)) and @@ -2702,7 +2704,7 @@ begin then ALen := MemManager.MemLimits.MaxStringLen * 2; - {$PUSH}{$Q-} + {$PUSH}{$Q-}{$R-} Addr.Address := Addr.Address + (AStartIndex - 1) * 2; {$POP} if not ( (MemManager.SetLength(ASubStr, ALen)) and @@ -4093,6 +4095,8 @@ begin // TODO: if FValueDone, and covers selected range, then use FValue; ASubStr := ''; Result := True; + if ALen <= 0 then + exit; dec(AStartIndex); if AStartIndex < 0 then begin // not supported, return partial diff --git a/components/fpdebug/fpdbgdwarffreepascal.pas b/components/fpdebug/fpdbgdwarffreepascal.pas index 5ff122f5b2..592b71006d 100644 --- a/components/fpdebug/fpdbgdwarffreepascal.pas +++ b/components/fpdebug/fpdbgdwarffreepascal.pas @@ -1113,7 +1113,7 @@ begin exit; while AParentClassIndex > 0 do begin - {$PUSH}{$Q-} + {$PUSH}{$Q-}{$R-} VmtAddr.Address := VmtAddr.Address + TDBGPtr(2 * ASizeOfAddr); {$POP} A := VmtAddr; @@ -1142,7 +1142,7 @@ begin dec(AParentClassIndex); end; - {$PUSH}{$Q-} + {$PUSH}{$Q-}{$R-} VmtAddr.Address := VmtAddr.Address + TDBGPtr(3 * ASizeOfAddr); {$POP} @@ -1179,7 +1179,7 @@ begin if AUnitName <> nil then begin // get vTypeInfo - {$PUSH}{$Q-} + {$PUSH}{$Q-}{$R-} VmtAddr.Address := VmtAddr.Address + TDBGPtr(4 * ASizeOfAddr); {$POP} @@ -1193,7 +1193,7 @@ begin //inc(Pointer(classtypeinfo), PByte(Pointer(classtypeinfo)+1)^ + 2); A := ClassNameAddr; - {$PUSH}{$Q-} + {$PUSH}{$Q-}{$R-} A.Address := A.Address + 1; {$POP} if not AContext.ReadUnsignedInt(A, SizeVal(1), NameLen) then begin @@ -1201,7 +1201,7 @@ begin AContext.ClearLastMemError; exit; end; - {$PUSH}{$Q-} + {$PUSH}{$Q-}{$R-} ClassNameAddr.Address := ClassNameAddr.Address + TDBGPtr(NameLen + 2) + TDBGPtr(2 * ASizeOfAddr + 2); if (ACompilerVersion >= $030300) then ClassNameAddr.Address := ClassNameAddr.Address + TDBGPtr(ASizeOfAddr); @@ -1674,7 +1674,7 @@ begin CalcBounds; if FHighBound < FLowBound then exit; // empty string - {$PUSH}{$Q-} + {$PUSH}{$Q-}{$R-} FullLen := FHighBound-FLowBound+1; {$POP} @@ -1705,10 +1705,12 @@ begin then ALen := MemManager.MemLimits.MaxStringLen; + if ALen <= 0 then + exit; t := TypeInfo; if t.Kind = skWideString then begin - {$PUSH}{$Q-} + {$PUSH}{$Q-}{$R-} Addr.Address := Addr.Address + (AStartIndex - 1) * 2; {$POP} if not ( (MemManager.SetLength(WResult, ALen)) and @@ -1720,7 +1722,7 @@ begin end else if Addr.Address = Address.Address + 1 then begin // shortstring - {$PUSH}{$Q-} + {$PUSH}{$Q-}{$R-} Addr.Address := Addr.Address + AStartIndex - 1; {$POP} if not ( (MemManager.SetLength(ASubStr, ALen)) and @@ -1782,7 +1784,7 @@ begin CalcBounds; if FHighBound < FLowBound then exit; // empty string - {$PUSH}{$Q-} + {$PUSH}{$Q-}{$R-} Len := FHighBound-FLowBound+1; {$POP} diff --git a/components/fpdebug/fppascalparser.pas b/components/fpdebug/fppascalparser.pas index 739fc00bb7..07339edfab 100644 --- a/components/fpdebug/fppascalparser.pas +++ b/components/fpdebug/fppascalparser.pas @@ -4990,9 +4990,10 @@ function TFpPasParserValueSlicedArray.GetMember(AIndex: Int64): TFpValue; begin if SlicePart.FCurrentIndex = AIndex then begin Result := FArraySlice.Items[0].ResultValue; - if Result <> nil then + if Result <> nil then begin Result.AddReference; Result.Reset; + end; exit; end;